Nginx
nginx 失敗,而網站仍然可以正常工作
描述
- 我根據本指南建構了我的 Django3、gunicorn、nginx、Ubuntu 18.04、Digital Ocean 項目。我只有一個問題,它不顯示 CSS 和所有其他靜態文件,如圖像。在整個指南之前,nginx 已經按照指南所說的給出了正確的答案,而且目前 html 站點仍然線上並正在執行
- 為了解決這個問題,我正在使用另一個指南來讓我的靜態文件顯示在我的網站上。我已經完成了創建者推薦的所有步驟,但在
我試過的
- 在以下每個步驟之後
$$ 1.2.3… $$命令我執行了以下命令來刷新:
python3 manage.py collectstatic
sudo nginx -t && sudo systemctl restart nginx
sudo systemctl restart gunicorn
- 1.RUN:
sudo ln -s /etc/nginx/sites-available/ch-project /etc/nginx/sites-enabled
- 1.結果:
ln: failed to create symbolic link '/etc/nginx/sites-enabled/ch-project': File exists
- 2.RUN:
/etc/nginx/sites-enabled/my-project
- 2.結果:
-bash: /etc/nginx/sites-enabled/my-project: Permission denied
- 3.RUN:
systemctl status nginx.service
- 3.結果:
● 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 Thu 2020-03-26 13:27:08 UTC; 13s ago Docs: man:nginx(8) Process: 11111 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS) Process: 11111 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE) Main PID: 11111 (code=exited, status=0/SUCCESS)
- 4.RUN:
sudo nginx -t
- 4.結果:
nginx: [emerg] open() "/etc/nginx/sites-enabled/myproject" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62 nginx: configuration file /etc/nginx/nginx.conf test failed
- 否則 Nginex 應該沒問題,因為網站上的 html 載入並執行良好。這個堆棧溢出文章說我也許應該對安全性做一些事情,
nginx.conf
但在那種情況下,他們談論的是一個 worldpres 網站,所以我不知道如何在這裡實現它。
- 我之前嘗試過這個堆棧溢出文章的答案,下面是它有一個子文章來進一步配置 RUN 的答案:
sudo nginx -c /etc/nginx/sites-enabled/default -t
- 6.結果:
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-enabled/default:21 nginx: configuration file /etc/nginx/sites-enabled/default test failed
靜態文件仍然無法載入,但 nginx 已使用以下命令修復。
- 從官方指南中的文件名中刪除意外創建的 myproject 文件,
/etc/nginx/sites-enabled/myproject
但 the_actual_myproject 具有不同的名稱 RUN:cd /etc/nginx/sites-enabled sudo rm myproject
- 跑:
namei -l /run/gunicorn.sock sudo systemctl restart gunicorn sudo systemctl daemon-reload sudo systemctl restart gunicorn.socket gunicorn.service sudo nginx -t && sudo systemctl restart nginx
- 結果:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
- 跑:
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: active (running) since Thu 2020-03-26 16:32:09 UTC; 7min ago Docs: man:nginx(8) Process: 11111 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, sta Process: 11111 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=ex Main PID: 11111 (nginx) Tasks: 2 (limit: 1152) CGroup: /system.slice/nginx.service