I've got nginx 1.8.1 on a server running FreeBSD 10.2. I'm trying to serve files from a subdirectory of /usr/local/www/
(which is default on FreeBSD), but for some reason, requests to the files I'm trying to access always result in a 404.
The file specifically is /usr/local/www/example.com/pubic_html/index.html
, with /usr/local/www
recursively owned by www:www
, the user and group of the nginx worker process, with permissions recusrively set to 755
.
My server
block, in /usr/local/etc/nginx/sites-available/example.com
:
server {
listen 80 default;
server_name example.com www.example.com;
root /usr/local/www/example.com/public_html;
location /app {
proxy_pass http://localhost:8080;
}
location / {
try_files $uri =404;
}
}
I'm honestly puzzled by this. I haven't had this issue on Linux with Nginx or Apache, and I haven't had this issue working with Apache on FreeBSD before, either. How can I get nginx to serve this static file?
EDIT: while requests for static files don't result in anything being logged to my nginx-error.log
, it does result in normal 404 hit records in the nginx-access.log
.
OK here's the thing: the default configurations for web servers in FreeBSD DO NOT use files inside the
sites-available
directory. Either you have to put the contents of the files inside/usr/local/etc/nginx/nginx.conf
or add this line to/usr/local/etc/nginx/nginx.conf
so that it will read files inside thesites-available
directory:The same behavior also applies to Apache on FreeBSD. (Probably on other web servers as well, but I have experience only with these two.)
Do you have other configuration files for Nginx?
I guess you have
listen <ip>
directive somewhere else so you should also uselisten <ip> default_server
orlisten <ip>:80 default_server
in yourexample.com
configuration.