
Tengo un problema al intentar llegar a mi servidor sólo a través de la IP en el puerto 80.
Si voy a la IP me sale la página de error nginx 404.
Así es como se ve mi configuración predeterminada:
# 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;
#}
}
Dentro /var/www/default
hay un archivo llamado index.html. Ahora a la parte extraña. Si cambio el puerto de escucha a 8888
nginx, el index.html se sirve correctamente. Sólo tengo 3 sitios y los otros son servidores virtuales, por lo que no tienen una directiva de escucha. Configuré la /var/www/default
carpeta en chmod 777
solo por ahora, todavía regresa 404
al puerto 80
.
Editar:
Revisé el registro de errores de nginx y se indicó esto:
2014/04/08 09:30:21 [error] 3349#0: *1 "/etc/nginx/html/index.html" is not found
Entonces surge la pregunta: ¿dónde está esta configuración que dice que /etc/nginx/html/index.html
es la raíz predeterminada?
Respuesta1
No tienes la default_server
opción en tu listen
directiva. Por lo tanto, la solicitud coincide con algún otro host virtual en su configuración de nginx.
Entonces, prueba esto como tu línea de escucha:
listen 80 default_server;
Entonces es posible que tengas que eliminarlos default_server
de otros hosts virtuales si tienen esa definición.
Otra cosa podría ser: ¿accedió al servidor mediante 127.0.0.1
o localhost
? server_name localhost
significa que el host virtual solo se usa cuando localhost
se usa en la URL.