
當我嘗試僅透過連接埠 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的檔案。現在到奇怪的部分。如果我將偵聽連接埠變更為8888
nginx,則可以正確服務 index.html。我只有 3 個站點,其他都是虛擬主機,因此它們沒有監聽指令。我暫時將/var/www/default
資料夾設為,仍然在 port 上返回。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 中使用時才使用虛擬主機。