0

Description

  • I have built my Django3, gunicorn, nginx, Ubuntu 18.04, Digital Ocean project based on this guide. I only had 1 problem that it does not shows the CSS and all other static files like images. Before during the whole guide nginx have given the correct answers as the guide says and also currently the html site still online and running
  • To solve this I was in the process of using this another guide to make my static files displayed on my site. I have done all the steps what the creator recommended but at the

What I have tried

  • After each step of the following [1.2.3...] commands I have executed the following commands to refresh:

    • 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.RESULT: -bash: /etc/nginx/sites-enabled/my-project: Permission denied

  • 3.RUN: systemctl status nginx.service

  • 3.RESULT:
● 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.RESULT:
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 should be Ok otherwise because the html on the website loads and works perfectly. This stack overflow post says I should maybe do something with the security of the nginx.conf but in that case they talk about a worldpres site so I don't know how to implement that here.
    1. I have tried this stack overflow post's answer previously, bellow the answer it has a subpost to further configure RUN: sudo nginx -c /etc/nginx/sites-enabled/default -t
  • 6.RESULT:
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
sogu
  • 213
  • 2
  • 4
  • 12

1 Answers1

0

The static files still don't load but nginx has been fixed with the following commands.

  • deleting accidentally created myproject file from /etc/nginx/sites-enabled/myproject what file name is in the official guide but the_actual_myproject has different name RUN:
cd /etc/nginx/sites-enabled
sudo rm myproject
  • RUN:
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
  • RESULT:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • RUN: systemctl status nginx.service

  • RESULT:

● 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
sogu
  • 213
  • 2
  • 4
  • 12