大网数据广告活动
服务器运维问答

Default server block keeps loading instead of the server block which has the website files

· 52CE 我爱测

It's my fresh installation of nginx on Ubuntu so I haven't messed up much and most of the tutorials are taken from DigitalOcean website. I have set up two server blocks (first is the default and second is for my website) but due …

问题原文

原帖链接 · Gurjyot Singh · CC BY-SA 3.0

It's my fresh installation of nginx on Ubuntu so I haven't messed up much and most of the tutorials are taken from DigitalOcean website. I have set up two server blocks (first is the default and second is for my website) but due to some issue, the default server block keeps loading even if I call for my website which is in secondary server block. My website is yoalfaaz.com and if I try to load it, then a file from default server loads up.

To be even more clear, the files of /var/www/html keeps loading, instead, I want to load files of /var/www/yoalfaaz.com/html.

Here's the sites-available/yoalfaaz.com file

server {
        listen 80 ;
        listen [::]:80 ;

        root /var/www/yoalfaaz.com/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name yoalfaaz.com www.yoalfaaz.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #

        location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
        deny all;
        }
}

And here's the error.log message

2018/02/18 06:47:02 [error] 28275#28275: *1656 directory index of "/var/www/html/" is forbidden, client: 47.89.22.200, server: [IP for server], request: "GET / HTTP/1.0", host: "www.yoalfaaz.com", referrer: "https://www.yoalfaaz.com"

I have also used the command nginx -t and everything is good with that. So can you please tell what the issue is here?

已采纳解答

原帖链接 · Gurjyot Singh · CC BY-SA 3.0

There was some problem with creating symbolic links to the files in sites-enabled. So I removed the files in sites-enabled from command

sudo rm /etc/nginx/sites-enabled/yoalfaaz.com

Then I again created symbolic links using the command

sudo ln -s /etc/nginx/sites-available/yoalfaaz.com /etc/nginx/sites-enabled/

and everything started to work again.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-02-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。