设置 root 后,nginx 配置仍然提供默认主页
nginx config still serving default home page after root has been set
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server{
server_name sample.com;
listen 80;
location = / {
root /root_path;
index index.html;
}
location / {
# root /root_path;
# index index.html;
# proxy_pass http://127.0.0.1:5200;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $host; # pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass
# proxy_http_version 1.1; # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
# WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection $connection_upgrade;
}
}
这只是“/etc/nginx/site-enable”中的配置文件,但仍然加载nginx默认页面。这怎么可能?如果默认根目录没有在服务器块中定义,而只在位置块中定义,那么根目录是否默认为 nginx 默认根目录?
我找到了我的问题的问题和解决方案。
"It should be noted that using an index file causes an internal redirect, and the request can be processed in a different location.
For example, with the following configuration:
location = / {
index index.html;
}
location / {
...
}
“/”请求实际上将在第二个位置处理为
“/index.html”。 "
我引用自
> http://nginx.org/en/docs/http/ngx_http_index_module.html
就我而言,我请求在第一个位置块中加载 index.html。
location = / { }
但 nginx 重定向并从第二个位置块捕获它。
location / { }
但是 index.html 文件在那里被注释了。所以它将加载默认的 nginx 页面。
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server{
server_name sample.com;
listen 80;
location = / {
root /root_path;
index index.html;
}
location / {
# root /root_path;
# index index.html;
# proxy_pass http://127.0.0.1:5200;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $host; # pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass
# proxy_http_version 1.1; # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
# WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection $connection_upgrade;
}
}
这只是“/etc/nginx/site-enable”中的配置文件,但仍然加载nginx默认页面。这怎么可能?如果默认根目录没有在服务器块中定义,而只在位置块中定义,那么根目录是否默认为 nginx 默认根目录?
我找到了我的问题的问题和解决方案。
"It should be noted that using an index file causes an internal redirect, and the request can be processed in a different location. For example, with the following configuration:
location = / { index index.html; } location / { ... }
“/”请求实际上将在第二个位置处理为 “/index.html”。 "
我引用自
> http://nginx.org/en/docs/http/ngx_http_index_module.html
就我而言,我请求在第一个位置块中加载 index.html。
location = / { }
但 nginx 重定向并从第二个位置块捕获它。
location / { }
但是 index.html 文件在那里被注释了。所以它将加载默认的 nginx 页面。