Trying to add second project on Nginx configuration

Hey

I am trying add a second project on the same port in the same Nginx configuration file. For the new project i have created Gunicorn service and socket file and enabled and both are active.

The server runs and i am able to see the test page but i am struggling to access my two application through the url’s. I really do think the problem is in this Nginx configuration file.

Things to Note. Don’t know if i should use root or alias.
I also have prefixes for both projects.

Project 1 - domestic_voicelogging

path('voicelogging/', include("voiceloggingApp.urls")),

Project 2 - django_referral

path('djangoprogram/', include('djangoprogram.urls')),

Here is the Nginx file:

server {
    listen 80;
    server_name 41.76.110.165;

    # Handle favicon
    location = /favicon.ico {
        access_log off;
        log_not_found off;
    }

    # Static files for Project 1
    location /domestic_voicelogging/static/ {
        alias /home/marco/domestic_voicelogging/staticfiles/;
    }

    # Static files for Project 2
    location /django_referral/static/ {
        alias /home/marco/django_referral/staticfiles/;
    }

    # Application requests for Project 1
    location /domestic_voicelogging/ {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
        rewrite ^/domestic_voicelogging/(.*)$ /$1 break;
    }

    # Application requests for Project 2
    location /django_referral/ {
        include proxy_params;
        proxy_pass http://unix:/run/django_referral.sock;
        rewrite ^/django_referral/(.*)$ /$1 break;
    }
}

Are you using Gunicorn? Each project has it’s own socket file? You need to post them here and also I suggest to check your permissions.

This is something we do regularly (multiple Django projects behind one nginx instance), so I know it can be done. (However, we don’t use a rewrite rule in nginx, we handle this within the uwsgi configuration, so I’m not exactly familiar with how you’re doing this.)

Anyway, can you provide more details about how exactly it’s failing and the symptoms you are seeing?

Can you show the relevant segments of your nginx and gunicorn logs for requests? Identify what the URL is that you’re issuing, and what the corresponding log entries are.

What about your static files, do you have them configured correctly? (If you try to reference a static file directly, e.g. https://yoursite.com/domestic_voicelogging/static/css/style.css for a file named style.css in a static/css directory in your project, does this work?)

Side note: The use of root vs alias for your static files is primarily a personal choice, and may depend upon how you’re setting your static file - related settings in your project.

Briefly, with root, the final physical path is root + location, where with alias, the final physical path is alias. (In either case, you need to ensure that the static template tag is generating urls like /domestic_voicelogging/static/ and not just /static/.)
Also, as a general principle I always recommend against trying to have nginx serve files from a personal home directory. I always configure STATIC_ROOT to reference a more nginx-friendly location such as /var/www/html.

Hey guys

@anefta

Yes I’m using gunicorn. Both projects have service and socket files.

First project domestic_voicelogging:

Socket - gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock
SocketUser=marco
SocketGroup=www-data
SocketMode=0660

[Install]
WantedBy=sockets.target

Service - gunicorn.service

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=marco
Group=www-data
WorkingDirectory=/home/marco/domestic_voicelogging
ExecStart=/home/marco/domestic_voicelogging/venv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          domestic_voicelogging.wsgi:application

[Install]
WantedBy=multi-user.target

Second project django_referral:

Socket - dajngo_referral.socket

[Unit]
Description=gunicorn socket for django_referral

[Socket]
ListenStream=/run/django_referral.sock
SocketUser=marco
SocketGroup=www-data
SocketMode=0660

[Install]
WantedBy=sockets.target

Service - django_referral.service

[Unit]
Description=gunicorn daemon for django_referral
Requires=django_referral.socket
After=network.target

[Service]
User=marco
Group=www-data
WorkingDirectory=/home/marco/django_referral
ExecStart=/home/marco/django_referral/venv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/django_referral.sock \
          django_referral.wsgi:application

[Install]
WantedBy=multi-user.target

i do think you might be on to something with the permission.
Here are the sock file permission:

[marco@mydjangoserver ~]$ ls -l /run/
total 28
drwxr-xr-x.  6 root     root      120 Jul  8 09:49 NetworkManager
-rw-------.  1 root     root        0 Jul  8 09:49 agetty.reload
-rw-r--r--.  1 root     root        4 Jul  8 09:49 auditd.pid
drwxr-xr-x.  2 root     root       80 Jul  8 09:49 blkid
drwxr-x---.  2 chrony   chrony     80 Jul  8 09:49 chrony
drwxr-xr-x.  2 root     root       40 Jul  8 09:49 chrony-dhcp
drwxr-xr-x.  2 root     root       40 Jul  8 09:49 console
drwxr-xr-x.  5 root     root      100 Sep 11 10:22 credentials
----------.  1 root     root        0 Jul  8 09:49 cron.reboot
-rw-r--r--.  1 root     root        4 Jul  8 09:49 crond.pid
drwx------.  2 root     root       40 Jul  8 09:49 cryptsetup
drwxr-xr-x.  2 root     root       60 Jul  8 09:49 dbus
srw-rw-rw-.  1 marco    www-data    0 Sep 11 10:33 django_referral.sock
drwxr-xr-x.  2 root     root       40 Jul  8 09:49 faillock
drwxr-x---.  2 root     root       40 Jul  8 09:49 firewalld
drwxr-xr-x.  2 root     root       60 Jul  8 09:48 fsck
srw-rw-rw-.  1 marco    www-data    0 Jul  9 09:37 gunicorn.sock
prw-------.  1 root     root        0 Jul  8 09:49 initctl
drwxr-xr-x.  4 root     root      100 Jul  8 09:48 initramfs
drwxr-xr-x.  3 root     root       80 Jul  8 09:49 lock
drwxr-xr-x.  3 root     root       60 Jul  8 09:48 log
-rw-r--r--.  1 root     root        0 Jul  8 09:49 motd
drwxr-xr-x.  2 root     root       40 Jul  8 09:49 motd.d
drwxr-xr-x.  2 root     root       40 Jul  8 09:48 mount
-rw-r--r--.  1 root     root        8 Sep 11 14:08 nginx.pid
drwxr-xr-x.  2 postgres postgres   80 Jul 24 11:20 postgresql
-rw-------.  1 root     root       25 Jul  8 09:49 qga.state
-rw-------.  1 root     root        3 Jul  8 09:49 rsyslogd.pid
drwxr-xr-x.  2 root     root       40 Jul  8 09:49 sepermit
drwxr-xr-x.  2 root     root       40 Jul  8 09:49 setrans
-rw-r--r--.  1 root     root        6 Jul 10 15:04 sshd.pid
drwx--x--x.  3 root     root       60 Jul  8 09:49 sudo
drwxr-xr-x. 21 root     root      540 Sep 11 11:52 systemd
drwxr-xr-x.  2 root     root       60 Jul  8 09:48 tmpfiles.d
drwxr-xr-x.  3 root     root       60 Jul  8 09:49 tpm2-tss
drwxr-xr-x.  6 root     root      140 Jul  8 11:01 udev
drwxr-xr-x.  3 root     root       60 Sep 11 13:37 user
-rw-rw-r--.  1 root     utmp     2304 Sep 11 14:18 utmp

this was the permission i kind of remeber using for the first project:

sudo chown -R marco:www-data domestic_voicelogging
sudo chmod -R 755 domestic_voicelogging
sudo chmod +x domestic_voicelogging/manage.py
sudo chown -R marco:www-data domestic_voicelogging/venv
sudo chmod -R 755 domestic_voicelogging/venv

@KenWhitesell
I don’t really know what i did with the rewrite i got it from the internet.

To be honest im not really sure what the problem is exactly but the nginx test is successful and the gunicorn service and socket all run adn are active. i tried just serving/deploy the second project and it works but the css isnt loading. To answer you No, i can not search the ccs file name in the search.

this is waht im trying to deploy just the 2de one and it is working but the css is loading:

server {
   listen 80;
   server_name 41.76.110.165;

   location = /favicon.ico { access_log off; log_not_found off; }
   location /static/ {
        root /home/marco/django_referral/staticfiles/;
   }

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


when i check this log:

sudo tail -f /var/log/nginx/error.log

this is the error:

(venv) [marco@mydjangoserver django_referral]$ sudo tail -f /var/log/nginx/error.log
2024/09/11 13:52:23 [error] 1418239#1418239: *5 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (13: Permission denied), client: 105.245.232.98, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 13:52:23 [error] 1418239#1418239: *3 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (13: Permission denied), client: 105.245.232.98, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:00:03 [error] 1418422#1418422: *1 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (13: Permission denied), client: 105.245.232.98, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:00:07 [error] 1418422#1418422: *3 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (13: Permission denied), client: 105.245.232.98, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:07:57 [error] 1418630#1418630: *3 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (13: Permission denied), client: 105.245.232.98, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:08:02 [error] 1418630#1418630: *1 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (13: Permission denied), client: 105.245.232.98, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:08:03 [error] 1418630#1418630: *3 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (13: Permission denied), client: 105.245.232.98, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:17:34 [error] 1418653#1418653: *6 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:17:35 [error] 1418653#1418653: *6 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 14:17:35 [error] 1418653#1418653: *8 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
^C

I am very unfamiliar with permission etc. Hope we can figure this out <3

To clarify, is the problem only with loading static files? Or is the problem with both accessing the application and the static files?

@KenWhitesell

First problem -Currently the problem is with loading the new project static files and that permissions.

The main goal is to run both projects using the same port but its important for me to get this new project up and running. Even if its just the new project for now.

Second problem - accessing the both application. I think the problem might be with the nginx config. When everything was in place i couldn’t access my projects through url’s.

What is the output of sudo nginx -t ?

@anefta

I run this quite often and its almost always successful:

(venv) [marco@mydjangoserver django_referral]$ sudo nginx -t
[sudo] password for marco:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
(venv) [marco@mydjangoserver django_referral]$

Nice, so nginx does not complain…
Try: sudo systemctl daemon-reload and then sudo systemctl restart nginx

Try to set the ownership to marco:www-data and permissions to 755
and check again the error.log file.

sudo chown -R marco:www-data /home/marco/django_referral/staticfiles
sudo chmod -R 755 /home/marco/django_referral/staticfiles

@anefta

Okay i changed the permission like that and this is the error log i get from:

sudo tail -f /var/log/nginx/error.log

(venv) [marco@mydjangoserver django_referral]$ sudo chown -R marco:www-data /home/marco/django_referral/staticfiles
(venv) [marco@mydjangoserver django_referral]$ sudo chmod -R 755 /home/marco/django_referral/staticfiles
(venv) [marco@mydjangoserver django_referral]$ sudo tail -f /var/log/nginx/error.log
2024/09/11 15:18:15 [error] 1419130#1419130: *22 open() "/home/marco/django_referral/staticfiles/static/admin/css/login.586129c60a93.css" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/admin/css/login.586129c60a93.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/admin/login/?next=/djangoprogram/admin/"
2024/09/11 15:18:15 [error] 1419130#1419130: *23 open() "/home/marco/django_referral/staticfiles/static/admin/css/nav_sidebar.269a1bd44627.css" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/admin/css/nav_sidebar.269a1bd44627.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/admin/login/?next=/djangoprogram/admin/"
2024/09/11 15:18:15 [error] 1419130#1419130: *24 open() "/home/marco/django_referral/staticfiles/static/admin/js/theme.ab270f56bb9c.js" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/admin/js/theme.ab270f56bb9c.js HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/admin/login/?next=/djangoprogram/admin/"
2024/09/11 15:18:15 [error] 1419130#1419130: *25 open() "/home/marco/django_referral/staticfiles/static/admin/js/nav_sidebar.3b9190d420b1.js" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/admin/js/nav_sidebar.3b9190d420b1.js HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/admin/login/?next=/djangoprogram/admin/"
2024/09/11 15:18:15 [error] 1419130#1419130: *19 open() "/home/marco/django_referral/staticfiles/static/admin/css/responsive.f6533dab034d.css" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/admin/css/responsive.f6533dab034d.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/admin/login/?next=/djangoprogram/admin/"
2024/09/11 15:18:21 [error] 1419130#1419130: *24 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:18:21 [error] 1419130#1419130: *25 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:18:23 [error] 1419130#1419130: *27 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:18:23 [error] 1419130#1419130: *27 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:18:23 [error] 1419130#1419130: *27 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"

Oh… My mind comes to somewhere that had caused me a lot of pain… Please tell me the user value on the nginx configuration in /etc/nginx/nginx.conf or /etc/nginx/sites-available/default

Is it like that? user www-data;
If so, change to user marco;
save the files, restart nginx, reload the daemon etc.

The user in my nginx config (/etc/nginx/nginx.conf)

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

change it to user marco;

@anefta

I changed it to marco, did the restarts. This is the error log still says permission denied:

(venv) [marco@mydjangoserver django_referral]$ sudo nano /etc/nginx/nginx.conf
(venv) [marco@mydjangoserver django_referral]$ sudo systemctl restart nginx
(venv) [marco@mydjangoserver django_referral]$ sudo systemctl daemon-reload
(venv) [marco@mydjangoserver django_referral]$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
(venv) [marco@mydjangoserver django_referral]$ sudo systemctl status nginx
sudo systemctl status gunicorn
● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
     Active: active (running) since Wed 2024-09-11 15:30:07 SAST; 1min 3s ago
   Main PID: 1419281 (nginx)
      Tasks: 2 (limit: 4692)
     Memory: 2.0M
        CPU: 40ms
     CGroup: /system.slice/nginx.service
             ├─1419281 "nginx: master process /usr/sbin/nginx"
             └─1419282 "nginx: worker process"

Sep 11 15:30:07 mydjangoserver.co.za systemd[1]: Starting The nginx HTTP and reverse proxy server...
Sep 11 15:30:07 mydjangoserver.co.za nginx[1419279]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Sep 11 15:30:07 mydjangoserver.co.za nginx[1419279]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Sep 11 15:30:07 mydjangoserver.co.za systemd[1]: Started The nginx HTTP and reverse proxy server.
● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; preset: disabled)
     Active: active (running) since Wed 2024-09-11 15:24:00 SAST; 7min ago
TriggeredBy: ● gunicorn.socket
   Main PID: 1419217 (gunicorn)
      Tasks: 4 (limit: 4692)
     Memory: 106.6M
        CPU: 1.032s
     CGroup: /system.slice/gunicorn.service
             ├─1419217 /home/marco/domestic_voicelogging/venv/bin/python3 /home/marco/domestic_voicelogging/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock >
             ├─1419231 /home/marco/domestic_voicelogging/venv/bin/python3 /home/marco/domestic_voicelogging/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock >
             ├─1419232 /home/marco/domestic_voicelogging/venv/bin/python3 /home/marco/domestic_voicelogging/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock >
             └─1419233 /home/marco/domestic_voicelogging/venv/bin/python3 /home/marco/domestic_voicelogging/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock >

Sep 11 15:24:00 mydjangoserver.co.za systemd[1]: Started gunicorn daemon.
Sep 11 15:24:00 mydjangoserver.co.za gunicorn[1419217]: [2024-09-11 15:24:00 +0200] [1419217] [INFO] Starting gunicorn 22.0.0
Sep 11 15:24:00 mydjangoserver.co.za gunicorn[1419217]: [2024-09-11 15:24:00 +0200] [1419217] [INFO] Listening at: unix:/run/gunicorn.sock (1419217)
Sep 11 15:24:00 mydjangoserver.co.za gunicorn[1419217]: [2024-09-11 15:24:00 +0200] [1419217] [INFO] Using worker: sync
Sep 11 15:24:00 mydjangoserver.co.za gunicorn[1419231]: [2024-09-11 15:24:00 +0200] [1419231] [INFO] Booting worker with pid: 1419231
Sep 11 15:24:00 mydjangoserver.co.za gunicorn[1419232]: [2024-09-11 15:24:00 +0200] [1419232] [INFO] Booting worker with pid: 1419232
Sep 11 15:24:00 mydjangoserver.co.za gunicorn[1419233]: [2024-09-11 15:24:00 +0200] [1419233] [INFO] Booting worker with pid: 1419233
lines 1-21/21 (END)
^C
(venv) [marco@mydjangoserver django_referral]$ sudo nginx -T
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user marco;

here is the error log:

(venv) [marco@mydjangoserver django_referral]$ sudo tail -f /var/log/nginx/error.log
2024/09/11 15:24:09 [error] 1419230#1419230: *3 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (13: Permission denied), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:31:39 [error] 1419282#1419282: *1 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:31:40 [error] 1419282#1419282: *1 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:31:40 [error] 1419282#1419282: *1 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:32:28 [error] 1419282#1419282: *1 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:32:29 [error] 1419282#1419282: *1 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:32:29 [error] 1419282#1419282: *1 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:32:31 [error] 1419282#1419282: *4 open() "/home/marco/django_referral/staticfiles/static/CSS/loginStyle.9b8774737cdc.css" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/CSS/loginStyle.9b8774737cdc.css HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:32:31 [error] 1419282#1419282: *4 open() "/home/marco/django_referral/staticfiles/static/images/LogoText.50a448bb095a.png" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoText.50a448bb095a.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"
2024/09/11 15:32:32 [error] 1419282#1419282: *4 open() "/home/marco/django_referral/staticfiles/static/images/LogoS.bd2ae9c34de7.png" failed (2: No such file or directory), client: 105.245.236.240, server: 41.76.110.165, request: "GET /static/images/LogoS.bd2ae9c34de7.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/djangoprogram/login/"

Note that was the wrong gunicorn status this is the correct one but also active(running):

(venv) [marco@mydjangoserver django_referral]$ sudo systemctl status django_referral
● django_referral.service - gunicorn daemon for django_referral
     Loaded: loaded (/etc/systemd/system/django_referral.service; enabled; preset: disabled)
     Active: active (running) since Wed 2024-09-11 11:49:00 SAST; 3h 47min ago
TriggeredBy: ● django_referral.socket
   Main PID: 1417073 (gunicorn)
      Tasks: 4 (limit: 4692)
     Memory: 70.6M
        CPU: 9.095s
     CGroup: /system.slice/django_referral.service
             ├─1417073 /home/marco/django_referral/venv/bin/python3 /home/marco/django_referral/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/django_referral.sock djang>
             ├─1417074 /home/marco/django_referral/venv/bin/python3 /home/marco/django_referral/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/django_referral.sock djang>
             ├─1417075 /home/marco/django_referral/venv/bin/python3 /home/marco/django_referral/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/django_referral.sock djang>
             └─1417076 /home/marco/django_referral/venv/bin/python3 /home/marco/django_referral/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/django_referral.sock djang>

Sep 11 15:17:04 mydjangoserver.co.za gunicorn[1417074]:  - - [11/Sep/2024:15:17:04 +0200] "GET /djangoprogram/admin/login/?next=/djangoprogram/admin/ HTTP/1.0" 200 4331 "http://41.76.110.1>
Sep 11 15:18:15 mydjangoserver.co.za gunicorn[1417075]:  - - [11/Sep/2024:15:18:15 +0200] "GET /djangoprogram/admin/login/?next=/djangoprogram/admin/ HTTP/1.0" 200 4331 "http://41.76.110.1>
Sep 11 15:18:21 mydjangoserver.co.za gunicorn[1417076]:  - - [11/Sep/2024:15:18:21 +0200] "GET /djangoprogram/login/ HTTP/1.0" 200 1920 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:13>
Sep 11 15:18:23 mydjangoserver.co.za gunicorn[1417074]:  - - [11/Sep/2024:15:18:23 +0200] "GET /djangoprogram/login/ HTTP/1.0" 200 1920 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:13>
Sep 11 15:24:05 mydjangoserver.co.za gunicorn[1417075]:  - - [11/Sep/2024:15:24:05 +0200] "GET /djangoprogram/login/ HTTP/1.0" 200 1920 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:13>
Sep 11 15:24:09 mydjangoserver.co.za gunicorn[1417076]:  - - [11/Sep/2024:15:24:09 +0200] "GET /djangoprogram/login/ HTTP/1.0" 200 1920 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:13>
Sep 11 15:27:23 mydjangoserver.co.za gunicorn[1417075]:  - - [11/Sep/2024:15:27:23 +0200] "GET / HTTP/1.0" 404 179 "-" "-"
Sep 11 15:31:39 mydjangoserver.co.za gunicorn[1417075]:  - - [11/Sep/2024:15:31:39 +0200] "GET /djangoprogram/login/ HTTP/1.0" 200 1920 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:13>
Sep 11 15:32:28 mydjangoserver.co.za gunicorn[1417075]:  - - [11/Sep/2024:15:32:28 +0200] "GET /djangoprogram/login/ HTTP/1.0" 200 1920 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:13>
Sep 11 15:32:31 mydjangoserver.co.za gunicorn[1417076]:  - - [11/Sep/2024:15:32:31 +0200] "GET /djangoprogram/login/ HTTP/1.0" 200 1920 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:13>
lines 1-24/24 (END)
^C

Post the output of sudo -u marco ls -l /home/marco/django_referral/staticfiles/static/

@anefta

That file does not exist?
Some path must be wrong yes?

(venv) [marco@mydjangoserver django_referral]$ sudo -u marco ls -l /home/marco/django_referraldjangoprogram//static/
ls: cannot access '/home/marco/django_referraldjangoprogram//static/': No such file or directory
(venv) [marco@mydjangoserver django_referral]$ sudo -u marco ls -l /home/marco/django_referral/staticfiles/static/
ls: cannot access '/home/marco/django_referral/staticfiles/static/': No such file or directory
(venv) [marco@mydjangoserver django_referral]$ sudo -u marco ls -l /home/marco/django_referral/staticfiles/
total 28
drwxr-xr-x. 2 marco www-data  4096 Sep 11 13:49 CSS
drwxr-xr-x. 2 marco www-data  4096 Sep 11 13:49 JS
drwxr-xr-x. 5 marco www-data  4096 Sep 11 09:34 admin
drwxr-xr-x. 2 marco www-data  4096 Sep 11 09:50 images
-rwxr-xr-x. 1 marco www-data 11880 Sep 11 13:49 staticfiles.json
(venv) [marco@mydjangoserver django_referral]$ sudo -u marco ls -l /home/marco/django_referral/djangoprogram/static
total 12
drwxr-xr-x. 2 marco www-data 4096 Sep 11 08:53 CSS
drwxr-xr-x. 2 marco www-data 4096 Sep 11 08:53 JS
drwxr-xr-x. 2 marco www-data 4096 Sep 11 08:53 images
(venv) [marco@mydjangoserver django_referral]$

Probably yes. We need to verify those things step by step.
STEP 1: First, set the correct ownership and permissions for your project files and directories, and ensure that Nginx (running as www-data) can access them.

# For domestic_voicelogging
sudo chown -R marco:www-data /home/marco/domestic_voicelogging
sudo chmod -R 755 /home/marco/domestic_voicelogging
sudo find /home/marco/domestic_voicelogging -type d -exec chmod 755 {} \;
sudo find /home/marco/domestic_voicelogging -type f -exec chmod 644 {} \;

# For django_referral
sudo chown -R marco:www-data /home/marco/django_referral
sudo chmod -R 755 /home/marco/django_referral
sudo find /home/marco/django_referral -type d -exec chmod 755 {} \;
sudo find /home/marco/django_referral -type f -exec chmod 644 {} \;

# Ensure Nginx can access the directories
sudo usermod -a -G marco www-data
sudo chmod g+x /home/marco

Test the paths with ls -la and print the results.
E.g sudo -u marco ls -la /home/marco/domestic_voicelogging

also let’s make the user again www-data

@anefta

I changed the path on the Nginx config and now the CSS is showing on the site:

server {
   listen 80;
   server_name 41.76.110.165;

   location = /favicon.ico { access_log off; log_not_found off; }
   location /staticfiles/ {
        root /home/marco/django_referral/;
   }

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

But this only the second project and it’s sort of running. I added a Django admin super user but when i try to log into the admin panel nothing happens. When i enter wrong details i do get the error check at the log in.

I ran those permission commands.

With this one i got this error:

(venv) [marco@mydjangoserver django_referral]$ sudo chown -R marco:www-data /home/marco/django_referral
sudo chmod -R 755 /home/marco/django_referral
sudo find /home/marco/django_referral -type d -exec chmod 755 {} \;
sudo find /home/marco/django_referral -type f -exec chmod 644 {} \;
(venv) [marco@mydjangoserver django_referral]$ sudo usermod -a -G marco www-data
usermod: user 'www-data' does not exist
(venv) [marco@mydjangoserver django_referral]$ sudo chmod g+x /home/marco
(venv) [marco@mydjangoserver django_referral]$

Here is sudo -u marco ls -la /home/marco/domestic_voicelogging:

(venv) [marco@mydjangoserver django_referral]$ sudo -u marco ls -la /home/marco/domestic_voicelogging
total 56
drwxr-xr-x. 7 marco www-data 4096 Jul 24 10:07 .
drwx--x---. 6 marco marco    4096 Sep 11 15:57 ..
-rwxr-xr-x. 1 marco www-data  251 Jul 10 10:47 .env
drwxr-xr-x. 8 marco www-data 4096 Aug 13 15:33 .git
-rwxr-xr-x. 1 marco www-data   66 Jul 24 10:07 .gitattributes
-rw-r--r--. 1 marco www-data 2763 Jul 24 10:07 .gitignore
-rwxr-xr-x. 1 marco www-data 1070 Jul 24 10:07 LICENSE
-rwxr-xr-x. 1 marco www-data   76 Jul 24 10:07 README.md
drwxr-xr-x. 3 marco www-data 4096 Jul 24 10:07 domestic_voicelogging
-rwxr-xr-x. 1 marco www-data  703 Jul 24 10:07 manage.py
-rwxr-xr-x. 1 marco www-data 1814 Jul 24 10:07 requirements.txt
drwxr-xr-x. 6 marco www-data 4096 Jul 24 10:17 staticfiles
drwxr-xr-x. 6 marco www-data 4096 Jul 10 10:34 venv
drwxr-xr-x. 6 marco www-data 4096 Jul 24 10:07 voiceloggingApp

Here is sudo -u marco ls -la /home/marco/django_referral:

(venv) [marco@mydjangoserver django_referral]$ sudo -u marco ls -la /home/marco/django_referral
total 56
drwxr-xr-x. 7 marco www-data 4096 Sep 11 09:20 .
drwx--x---. 6 marco marco    4096 Sep 11 15:57 ..
-rw-r--r--. 1 marco www-data  406 Sep 11 09:22 .env
drwxr-xr-x. 8 marco www-data 4096 Sep 11 08:53 .git
-rw-r--r--. 1 marco www-data   66 Sep 11 08:53 .gitattributes
-rw-r--r--. 1 marco www-data 2774 Sep 11 09:23 .gitignore
-rw-r--r--. 1 marco www-data 1070 Sep 11 08:53 LICENSE
-rw-r--r--. 1 marco www-data   64 Sep 11 08:53 README.md
drwxr-xr-x. 3 marco www-data 4096 Sep 11 09:23 django_referral
drwxr-xr-x. 6 marco www-data 4096 Sep 11 09:23 djangoprogram
-rw-r--r--. 1 marco www-data  671 Sep 11 08:53 manage.py
-rw-r--r--. 1 marco www-data  426 Sep 11 09:15 requirements.txt
drwxr-xr-x. 6 marco www-data 4096 Sep 11 13:49 staticfiles
drwxr-xr-x. 5 marco www-data 4096 Sep 11 08:55 venv

Do you want me to change this ‘user marco;’ back to nginx or www-data?

Yes please, try nginx first and then www-data - if the first fails.