设置服务器块后,Nginx 不再服务我的域名

问题描述 投票:0回答:2

我正在将我的 MERN 应用程序部署到 Digital Ocean Droplet(Ubuntu 20.04 服务器)。

我按照以下教程中的步骤安装了 Nginx。 [我已完成前面的所有步骤]

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04

当我访问

http://134.122.112.22
时,我看到了 Nginx 登录页面,正如预期的那样。

但是,设置服务器块后,当我访问

http://sundaray.io
时,出现以下错误。

sundaray.io
是我的域名。

当我运行命令

/var/log/nginx/error.log
时,我看到以下内容:

如何修复该错误?

编辑-1

服务器块 为了创建服务器块,我按顺序执行了以下命令:

  1. mkdir -p /var/www/sundaray.io/html
  2. nano /etc/nginx/sites-available/sundaray.io
    然后,我粘贴了以下配置块。
server {
        listen 80;
        listen [::]:80;

        root /var/www/sundaray.io/html;
        index index.html index.htm index.nginx-debian.html;

        server_name sundaray.io www.sundaray.io;

        location / {
                try_files $uri $uri/ =404;
        }
}

错误 执行命令

cat /var/log/nginx/error.log
给出了以下结果:

编辑-2

执行

chown -R nginx:nginx /var/www/sundaray.io/html
抛出以下错误:

编辑-3

执行

ps -elf |grep nginx
给出以下结果:

编辑-4 当我执行命令

ls /var/www/sundaray.io/html
时,我得到以下结果:

nginx webserver web-deployment digital-ocean nginx-reverse-proxy
2个回答
0
投票

1.
chmod 777
从来都不是一个好主意。

NGINX 在 runuser 下运行。如何查看运行用户:

ps -elf |grep nginx
。正常情况下会是
nginx
。不要使用
777
(向所有人开放),而是使用
chmod -R 755 /path/to/folder
chown -R nginx:nginx /path/to/folder

但同意。对于故障排除,可以使用它。但回到你的问题。

2.目录列表已禁用。

错误告诉你 nginx 无法列出目录内容。这是默认行为。确保

root /var/www/sundaray.io/html;

这条路径存在并且

index index.html index.htm index.nginx-debian.html;

找到其中一个文件!

如果没有这些文件中的任何一个,NGINX 就无法加载

/
上的默认索引文件。将一些东西放入
/var/www/sundaray.io/html
,例如

printf "<html>\n<body>\n<h1>Hello from NGINX</h1>\n</body>\n</html>" > /var/www/sundaray.io/html/index.html && chown nginx:nginx /var/www/sundaray.io/html/index.html
。这应该会为您生成一个index.html。

如果您只想在没有任何文件的情况下测试服务器配置:

location / {
  return 200 "Hello on $host$uri\n";
}

0
投票

对我来说,这是因为我返回了 https,但没有设置我的加密证书。

我使用 certbot 进行了设置,现在它们可以工作了。 https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04

© www.soinside.com 2019 - 2024. All rights reserved.