【问题标题】:nginx config still serving default home page after root has been set设置 root 后,nginx 配置仍提供默认主页
【发布时间】:2018-12-05 05:22:25
【问题描述】:
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默认页面。这怎么可能?如果默认 root 没有在 server 块中定义,而只是在 location 块中,root 是否默认为 nginx 默认根目录?

【问题讨论】:

  • 您在浏览器中使用sample.com 吗? include /etc/nginx/site-enable/*.conf; 是否存在于 nginx.conf
  • 是的,但配置文件中没有任何包含。
  • Nginx 使用nginx.conf 读取配置。如果没有includeNginx 无法读取你的配置文件
  • " 包含 /etc/nginx/conf.d/*.conf; 包含 /etc/nginx/sites-enabled/*; " 抱歉,"nginx.conf" 中有包含

标签: nginx nginx-config


【解决方案1】:

我为我的问题找到了问题和解决方案。

"需要注意的是,使用索引文件会导致内部重定向,请求可以在不同的位置处理。 例如,使用以下配置:

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 页面。

【讨论】:

    猜你喜欢
    • 2010-10-01
    • 1970-01-01
    • 2016-11-29
    • 2014-09-03
    • 2019-02-12
    • 2013-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    相关资源
    最近更新 更多