当我通过链接到启用站点的目录启用文件时出现 Nginx 问题

Nginx problem when i enabled the file by linking to the sites-enabled dir

我在网上的好朋友。 我正在做一些关于 Nginx 的事情,以部署我由 Django、Postgresql、Gunicorn、Nginx 和 DigitalOcean 制作的应用程序。 首先,Github gist 中的项目名称是 btre_project,但我的应用程序的项目名称是 pfc_calc。考虑到名称 dif,我通过复制并粘贴要点上的行来创建项目文件夹。

sudo nano /etc/nginx/sites-available/pfc_calc

然后,复制代码并将其粘贴到我刚刚制作的文件中。

server {
    listen 80;
    server_name 104.248.152.6;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/djangoadmin/pyapps/pfc_calc;
    }
    
    location /media/ {
        root /home/djangoadmin/pyapps/pfc_calc;    
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

但是,这是我犯了错误并得到错误的地方 我傻到忘了把btre_project改成pfc_calc

sudo ln -s /etc/nginx/sites-available/btre_project /etc/nginx/sites-enabled

因为我注意到那个错误,所以我再次输入了这一行。

sudo ln -s /etc/nginx/sites-available/pfc_calc /etc/nginx/sites-enabled

我以为可以,我的错误是在桥下,但事实并非如此。 当我输入这一行时

sudo nginx -t

出现以下错误。

nginx: [emerg] open() "/etc/nginx/sites-enabled/btre_project" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed

我想我需要删除我输入时错误创建的文件

sudo ln -s /etc/nginx/sites-available/btre_project /etc/nginx/sites-enabled

有什么帮助吗??

下面是终端中的连续代码

djangoadmin@ubuntu1:~/pyapps/pfc_calc$ sudo systemctl restart nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
djangoadmin@ubuntu1:~/pyapps/pfc_calc$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2021-07-20 01:42:48 UTC; 26s ago
     Docs: man:nginx(8)
  Process: 9926 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=
  Process: 9928 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAI
 Main PID: 28967 (code=exited, status=0/SUCCESS)
 ^X

我认为问题是因为它无法解析指向您指定的第一个 conf 的符号链接。如果您可以删除 /etc/nginx/sites-enabled 中的 btre_project 那么您就可以开始了。

PS:我在全新的 nginx 安装上对其进行了测试,并且能够重现您遇到的确切错误