NGNIX设置无法更改默认index.html



i通过nginx配置静态站点,并在conf.d目录下包含我的设置。听端口80。

但是我发现当我请求URL时,nginx总是重定向默认页面/usr/share/nginx/html/index.html

我的配置似乎确实有效,因为所有访问日志都写入了我的访问日志设置,如果我将index.html更改为我的目录中的其他名称(例如i.html),并请求url mysite.com/i.html,我可以访问正确的页面。

所以,似乎nginx重定向所有index.html to默认一个。

我尝试更改默认端口/服务器名称/root,并注释默认设置,甚至关闭Selinux,上面都无法正常工作,它确实使我疯狂。

任何人可以帮我吗?

我在CentOS 7.2

上使用Nginx版本1.10.2

和以下是我的网站设置:

# the upstream component nginx needs to connect to
upstream blog {
    server 0.0.0.0:80; # for a web port socket (we'll use this first) 
}
# configuration of the server
server {
    # the port your site will be served on
    listen      80 default_server;
    listen      [::]:80 default_server ipv6only=on;
    # the domain name it will serve for
    server_name mysite.com;
    charset     utf-8;
    access_log  /var/log/blog/access.log;
    error_log  /var/log/blog/error.log;
    # max upload size
    client_max_body_size 75M;   # adjust to taste
    # Finally, send all non-media requests to the Django server.
    location / { try_files $uri @blog; }
    location @blog{
    root /home/work/projects/blog/public/;
    index  index.html index.htm;
    uwsgi_read_timeout 120s;
    uwsgi_send_timeout 120s;
    }
}

和/etc/nginx/nginx.conf是

server {
    # listen       8000 default_server;
    # listen       [::]:8000 default_server;
    # server_name  not;
    # root         /usr/share/nginx/html;
    # Load configuration files for the default server block.
    # include /etc/nginx/default.d/*.conf;
    # location / {
    # }
    error_page 404 /404.html;
        location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

这没有道理:

location / { 
    try_files $uri @blog;
}
location @blog{
    root /home/work/projects/blog/public/;
    index  index.html index.htm;
    uwsgi_read_timeout 120s;
    uwsgi_send_timeout 120s;
}

缺少root指令意味着第一个try_files将在默认位置寻找文件。

您只需要rootindex指令在server上下文中:

例如:

root /home/work/projects/blog/public;
index index.html index.htm;
location / { 
    try_files $uri $uri/ =404;
}

有关详细信息,请参见此文档。

相关内容

最新更新