I have a problem when trying to reach my server only via the IP on port 80.
If I go to the IP I get the nginx 404 error page.
This is what my default config looks like:
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
# Document root
root /var/www/default;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
# Only for nginx-naxsi : process denied requests
#location /RequestDenied {
# For example, return an error code
#return 418;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/www;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Inside the /var/www/default
there is a file named index.html. Now to the weird part. If I change the listen port to 8888
nginx serves the index.html correctly. I only have 3 sites and the other ones are virtual hosts, so they don't have a listen directive. I've set the /var/www/default
folder to chmod 777
just for now, still returns 404
on port 80
.
Edit:
I've checked the error log of nginx and this was stated:
2014/04/08 09:30:21 [error] 3349#0: *1 "/etc/nginx/html/index.html" is not found
The question then begs, where is this config that says that /etc/nginx/html/index.html
is the default root?
Best Answer
You don't have the
default_server
option on yourlisten
directive. Therefore the request matches some other virtual host in your nginx configuration.So, try this as your listen line:
Then you might have to remove the
default_server
from other virtual hosts if they have that definition.Another thing might be, did you access the server using
127.0.0.1
orlocalhost
?server_name localhost
means that the virtual host is only used whenlocalhost
is used in the URL.