加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 21:27:41 所属栏目:Nginx 来源:网络整理
导读:尝试仅通过端口80上的IP访问我的服务器时出现问题. 如果我转到IP,我会得到nginx 404错误页面. 这是我的默认配置: # You may add here your# server {# ...# }# statements for each of your virtual hosts to this fileserver { listen 80; ## listen for i

尝试仅通过端口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时才使用虚拟主机.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读