描述
- 我已经基于此构建了我的 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.运行:
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.运行:
/etc/nginx/sites-enabled/my-project
2.结果:
-bash: /etc/nginx/sites-enabled/my-project: Permission denied
3.运行:
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.运行:
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 网站,所以我不知道如何在这里实现这一点。
- Nginex 应该没问题,因为网站上的 html 加载和运行正常。这堆栈溢出帖子说我应该对安全性做些什么,
- 我试过堆栈溢出之前已经发布过答案,在答案下方有一个子帖子可以进一步配置 RUN:
sudo nginx -c /etc/nginx/sites-enabled/default -t
- 我试过堆栈溢出之前已经发布过答案,在答案下方有一个子帖子可以进一步配置 RUN:
- 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
答案1
静态文件仍然无法加载,但 nginx 已使用以下命令修复。
- 删除意外创建的 myproject 文件,
/etc/nginx/sites-enabled/myproject
文件名与官方指南中的一致,但 the_actual_myproject 的名称不同,运行:
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