【问题标题】:nginx fails while the website somehow still worksnginx 失败,而网站仍然可以正常工作
【发布时间】:2020-07-07 06:36:50
【问题描述】:

说明

  • 我已经基于guide 构建了我的 Django3、gunicorn、nginx、Ubuntu 18.04、Digital Ocean 项目。我只有一个问题,它不显示 CSS 和所有其他静态文件,如图像。在整个指南之前,nginx 已经按照指南的说法给出了正确的答案,而且目前 html 网站仍然在线并运行
  • 为了解决这个问题,我正在使用这个another guide 来让我的静态文件显示在我的网站上。 我已经完成了创作者推荐的所有步骤,但在

我的尝试

  • 在以下 [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.RESULT: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.运行: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
    1. 否则 Nginex 应该没问题,因为网站上的 html 可以正常加载和运行。这篇stack overflow 帖子说我也许应该对nginx.conf 的安全性做一些事情,但在这种情况下,他们谈论的是一个worldpres 网站,所以我不知道如何在这里实现它。
    1. 我之前尝试过stack overflow这个帖子的答案,下面的答案有一个子帖子来进一步配置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

【问题讨论】:

  • 你能把你的配置文件的内容粘贴到/etc/nginx/sites-enabled吗?

标签: django ubuntu nginx ubuntu-18.04 django-3.0


【解决方案1】:

静态文件仍然无法加载,但 nginx 已使用以下命令修复。

  • /etc/nginx/sites-enabled/myproject删除意外创建的myproject文件,官方指南中的文件名是什么,但_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

【讨论】:

    猜你喜欢
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    相关资源
    最近更新 更多