
포트 80의 IP를 통해서만 내 서버에 연결하려고 할 때 문제가 있습니다.
IP로 이동하면 nginx 404 오류 페이지가 나타납니다.
내 기본 구성은 다음과 같습니다.
# 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;
#}
}
그 안에 /var/www/default
index.html이라는 파일이 있습니다. 이제 이상한 부분으로 넘어갑니다. 청취 포트를 nginx로 변경하면 8888
index.html이 올바르게 제공됩니다. 나는 3개의 사이트만 가지고 있고 다른 사이트는 가상 호스트이므로 청취 지시문이 없습니다. 지금은 /var/www/default
폴더를 으로 설정했지만 여전히 포트로 반환됩니다 .chmod 777
404
80
편집하다:
nginx의 오류 로그를 확인했는데 다음과 같이 명시되어 있습니다.
2014/04/08 09:30:21 [error] 3349#0: *1 "/etc/nginx/html/index.html" is not found
그러면 질문이 생깁니다. /etc/nginx/html/index.html
기본 루트라고 말하는 이 구성은 어디에 있습니까?
답변1
default_server
귀하의 지시문 에는 옵션이 없습니다 listen
. 따라서 요청은 nginx 구성의 다른 가상 호스트와 일치합니다.
따라서 다음을 청취 라인으로 사용해 보십시오.
listen 80 default_server;
default_server
그런 다음 다른 가상 호스트에 해당 정의가 있는 경우 이를 제거해야 할 수도 있습니다 .
127.0.0.1
또 다른 문제는 또는 을 사용하여 서버에 액세스했습니까 localhost
? server_name localhost
가상 호스트는 localhost
URL에 사용될 때만 사용된다는 의미입니다.