nginx默认根在端口80上返回404

前端之家收集整理的这篇文章主要介绍了nginx默认根在端口80上返回404前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

尝试仅通过端口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的文件.现在到了奇怪的部分.如果我将listen端口更改为8888,则Nginx会正确地为index.html提供服务.我只有3个站点而其他站点是虚拟主机,因此它们没有listen指令.我现在将/ var / www / default文件夹设置为chmod 777,仍然在端口80上返回404.

编辑:
我检查了Nginx错误日志,并说明了这一点:
2014/04/08 09:30:21 [错误] 3349#0:* 1“/etc/Nginx/html/index.html”未找到

然后问题是,这个配置在哪里说/etc/Nginx/html/index.html是默认的根?

最佳答案
您的listen指令上没有default_server选项.因此,请求与Nginx配置中的其他虚拟主机匹配.

所以,试试这个作为你的听线:

listen 80 default_server;

然后,如果具有该定义,则可能必须从其他虚拟主机中删除default_server.

另一件事可能是,您是否使用127.0.0.1或localhost访问服务器? server_name localhost表示仅在URL中使用localhost时才使用虚拟主机.

原文链接:https://www.f2er.com/nginx/435636.html

猜你在找的Nginx相关文章