Trying to add second project on Nginx configuration

Whether you have one file for each project or one file for both projects together is entirely up to you. It makes no difference to nginx, because everything in sites-enabled should be included. (I say should, because this relies upon the existence of the include /etc/nginx/sites-enabled/*; line that is currently missing from your nginx.conf file.

Yes, and if it’s the configuration you want, then create the symlink to it from sites-enabled. (And unlink the existing file there.)

@KenWhitesell

So moved mydjangoserver config file and created a new link:

[marco@mydjangoserver ~]$ sudo mv /etc/nginx/conf.d/mydjangoserver.conf /etc/nginx/sites-available/
[marco@mydjangoserver ~]$ sudo ln -s /etc/nginx/sites-available/mydjangoserver.conf /etc/nginx/sites-enabled/mydjangoserver.conf
[marco@mydjangoserver ~]$ sudo unlink /etc/nginx/sites-enabled/domestic_voicelogging
[marco@mydjangoserver ~]$ ls -l /etc/nginx/sites-enabled/
total 0
lrwxrwxrwx. 1 root root 46 Sep 17 08:41 mydjangoserver.conf -> /etc/nginx/sites-available/mydjangoserver.conf
[marco@mydjangoserver ~]$ readlink /etc/nginx/sites-enabled/domestic_voicelogging
[marco@mydjangoserver ~]$ readlink /etc/nginx/sites-enabled/mydjangoserver.conf
/etc/nginx/sites-available/mydjangoserver.conf
[marco@mydjangoserver ~]$ ls -l /etc/nginx/sites-available/
total 8
-rw-r--r--. 1 root root 339 Sep 13 09:40 domestic_voicelogging
-rw-r--r--. 1 root root 770 Sep 13 11:21 mydjangoserver.conf
[marco@mydjangoserver ~]$ find /etc/nginx/sites-enabled/ -type l -ls
   133177      0 lrwxrwxrwx   1 root     root           46 Sep 17 08:41 /etc/nginx/sites-enabled/mydjangoserver.conf -> /etc/nginx/sites-available/mydjangoserver.conf
[marco@mydjangoserver ~]$ sudo systemctl restart nginx
[marco@mydjangoserver ~]$ ls -l /run/gunicorn.sock
ls -l /run/django_referral.sock
srw-rw----. 1 nginx www-data 0 Jul  9 09:37 /run/gunicorn.sock
srw-rw----. 1 nginx www-data 0 Sep 12 08:37 /run/django_referral.sock
[marco@mydjangoserver ~]$ ls -l /etc/nginx/sites-available/
total 8
-rw-r--r--. 1 root root 339 Sep 13 09:40 domestic_voicelogging
-rw-r--r--. 1 root root 770 Sep 13 11:21 mydjangoserver.conf
[marco@mydjangoserver ~]$ ls -l /etc/nginx/sites-enabled/
total 0
lrwxrwxrwx. 1 root root 46 Sep 17 08:41 mydjangoserver.conf -> /etc/nginx/sites-available/mydjangoserver.conf
[marco@mydjangoserver ~]$

I restarted everything and this is the nginx error log:

[marco@mydjangoserver ~]$ sudo tail -f /var/log/nginx/error.log
2024/09/17 07:48:04 [error] 1544243#1544243: *2088 open() "/usr/share/nginx/html/wp-content/plugins/jquery-html5-file-upload/readme.txt" failed (2: No such file or directory), client: 194.38.23.16, server: 41.76.110.165, request: "GET /wp-content/plugins/jquery-html5-file-upload/readme.txt HTTP/1.1", host: "royalbotania.co.za"
2024/09/17 07:48:31 [error] 1544243#1544243: *2089 open() "/usr/share/nginx/html/wp-content/plugins/jquery-html5-file-upload/readme.txt" failed (2: No such file or directory), client: 194.38.23.16, server: 41.76.110.165, request: "GET /wp-content/plugins/jquery-html5-file-upload/readme.txt HTTP/1.1", host: "simplyoutdoors.co.za"
2024/09/17 08:25:20 [error] 1544243#1544243: *2094 open() "/usr/share/nginx/html/cgi-bin/luci/;stok=/locale" failed (2: No such file or directory), client: 45.148.10.242, server: 41.76.110.165, request: "GET /cgi-bin/luci/;stok=/locale HTTP/1.1", host: "41.76.110.165:80"
2024/09/17 08:26:34 [error] 1544243#1544243: *2095 open() "/usr/share/nginx/html/druid/index.html" failed (2: No such file or directory), client: 13.91.177.99, server: 41.76.110.165, request: "GET /druid/index.html HTTP/1.1", host: "41.76.110.165"
2024/09/17 08:41:35 [notice] 1557007#1557007: signal process started
2024/09/17 08:41:42 [error] 1557008#1557008: *2101 open() "/usr/share/nginx/html/static/images/Login.png" failed (2: No such file or directory), client: 41.3.141.88, server: 41.76.110.165, request: "GET /static/images/Login.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/domestic_voicelogging/static/CSS/login.css"
2024/09/17 08:45:26 [error] 1557008#1557008: *2117 open() "/usr/share/nginx/html/static/images/Login.png" failed (2: No such file or directory), client: 41.3.141.88, server: 41.76.110.165, request: "GET /static/images/Login.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/domestic_voicelogging/static/CSS/login.css"
2024/09/17 08:45:29 [error] 1557008#1557008: *2117 open() "/usr/share/nginx/html/static/images/b1.png" failed (2: No such file or directory), client: 41.3.141.88, server: 41.76.110.165, request: "GET /static/images/b1.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/domestic_voicelogging/static/CSS/homeStyle.css"
2024/09/17 08:48:54 [error] 1557008#1557008: *2120 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 66.249.66.165, server: 41.76.110.165, request: "GET /robots.txt HTTP/1.1", host: "www.vmcloudhost.interdevsystems.co.za"
2024/09/17 08:54:29 [error] 1557088#1557088: *6 open() "/usr/share/nginx/html/static/images/Login.png" failed (2: No such file or directory), client: 41.3.141.88, server: 41.76.110.165, request: "GET /static/images/Login.png HTTP/1.1", host: "41.76.110.165", referrer: "http://41.76.110.165/domestic_voicelogging/static/CSS/login.css"
^C

My static files DIR’s do exist:

[marco@mydjangoserver ~]$ ls -l /var/www/html/domestic_voicelogging/static/
ls -l /var/www/html/django_referral/static/
total 28
drwxr-sr-x. 2 marco www-data  4096 Sep 13 13:22 CSS
drwxr-sr-x. 2 marco www-data  4096 Sep 13 13:22 JS
drwxr-sr-x. 5 marco www-data  4096 Sep 13 10:09 admin
drwxr-sr-x. 2 marco www-data  4096 Sep 13 10:09 images
-rw-r--r--. 1 marco www-data 10815 Sep 13 13:22 staticfiles.json
total 28
drwxr-sr-x. 2 marco www-data  4096 Sep 13 11:19 CSS
drwxr-sr-x. 2 marco www-data  4096 Sep 13 11:19 JS
drwxr-sr-x. 5 marco www-data  4096 Sep 13 10:08 admin
drwxr-sr-x. 2 marco www-data  4096 Sep 13 10:08 images
-rw-r--r--. 1 marco www-data 11880 Sep 13 11:19 staticfiles.json

The site works and i can access both projects but:
Problem 1 - domestic_voicelogging - the image files wont load but the css is there.
Problem 2 - django_referral - Unsure about image files loading but css is there. I cant log into the project or admin(django) but i can access the admin page.

Every time i log in i just get redirected and i checked the database the user does exist, password also correct cause it will tell me if credentials are incorrect:

(http://41.76.110.165/djangoprogram/login/?next=/djangoprogram/home/)

Just in case you wanted it ’ sudo nginx -T ’ + ’ nginx -V ’

[marco@mydjangoserver ~]$ nginx -V
nginx version: nginx/1.20.1
built by gcc 11.3.1 20221121 (Red Hat 11.3.1-4) (GCC)
built with OpenSSL 3.0.7 1 Nov 2022
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,-E'
[marco@mydjangoserver ~]$ 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
# 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 nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
# include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    server_names_hash_bucket_size 64;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

#    server {
#        listen       80;
#        listen       [::]:80;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#        location = /404.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#        location = /50x.html {
#        }
#    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}


# configuration file /etc/nginx/mime.types:

types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/xml                                         xml;
    image/gif                                        gif;
    image/jpeg                                       jpeg jpg;
    application/javascript                           js;
    application/atom+xml                             atom;
    application/rss+xml                              rss;

    text/mathml                                      mml;
    text/plain                                       txt;
    text/vnd.sun.j2me.app-descriptor                 jad;
    text/vnd.wap.wml                                 wml;
    text/x-component                                 htc;

    image/png                                        png;
    image/svg+xml                                    svg svgz;
    image/tiff                                       tif tiff;
    image/vnd.wap.wbmp                               wbmp;
    image/webp                                       webp;
    image/x-icon                                     ico;
    image/x-jng                                      jng;
    image/x-ms-bmp                                   bmp;

    font/woff                                        woff;
    font/woff2                                       woff2;

    application/java-archive                         jar war ear;
    application/json                                 json;
    application/mac-binhex40                         hqx;
    application/msword                               doc;
    application/pdf                                  pdf;
    application/postscript                           ps eps ai;
    application/rtf                                  rtf;
    application/vnd.apple.mpegurl                    m3u8;
    application/vnd.google-earth.kml+xml             kml;
    application/vnd.google-earth.kmz                 kmz;
    application/vnd.ms-excel                         xls;
    application/vnd.ms-fontobject                    eot;
    application/vnd.ms-powerpoint                    ppt;
    application/vnd.oasis.opendocument.graphics      odg;
    application/vnd.oasis.opendocument.presentation  odp;
    application/vnd.oasis.opendocument.spreadsheet   ods;
    application/vnd.oasis.opendocument.text          odt;
    application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                     pptx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                     xlsx;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                     docx;
    application/vnd.wap.wmlc                         wmlc;
    application/x-7z-compressed                      7z;
    application/x-cocoa                              cco;
    application/x-java-archive-diff                  jardiff;
    application/x-java-jnlp-file                     jnlp;
    application/x-makeself                           run;
    application/x-perl                               pl pm;
    application/x-pilot                              prc pdb;
    application/x-rar-compressed                     rar;
    application/x-redhat-package-manager             rpm;
    application/x-sea                                sea;
    application/x-shockwave-flash                    swf;
    application/x-stuffit                            sit;
    application/x-tcl                                tcl tk;
    application/x-x509-ca-cert                       der pem crt;
    application/x-xpinstall                          xpi;
    application/xhtml+xml                            xhtml;
    application/xspf+xml                             xspf;
    application/zip                                  zip;

    application/octet-stream                         bin exe dll;
    application/octet-stream                         deb;
    application/octet-stream                         dmg;
    application/octet-stream                         iso img;
    application/octet-stream                         msi msp msm;

    audio/midi                                       mid midi kar;
    audio/mpeg                                       mp3;
    audio/ogg                                        ogg;
    audio/x-m4a                                      m4a;
    audio/x-realaudio                                ra;

    video/3gpp                                       3gpp 3gp;
    video/mp2t                                       ts;
    video/mp4                                        mp4;
    video/mpeg                                       mpeg mpg;
    video/quicktime                                  mov;
    video/webm                                       webm;
    video/x-flv                                      flv;
    video/x-m4v                                      m4v;
    video/x-mng                                      mng;
    video/x-ms-asf                                   asx asf;
    video/x-ms-wmv                                   wmv;
    video/x-msvideo                                  avi;
}

# configuration file /etc/nginx/sites-enabled/mydjangoserver.conf:
server {
    listen 80;
    server_name 41.76.110.165;

    # Static files for Project 1
    location /domestic_voicelogging/static/ {
        alias /var/www/html/domestic_voicelogging/static/;
    }

    # Static files for Project 2
    location /django_referral/static/ {
        alias /var/www/html/django_referral/static/;
    }

    # Application requests for Project 1
    location /voicelogging/ {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    # Application requests for Project 2
    location /djangoprogram/ {
        include proxy_params;
        proxy_pass http://unix:/run/django_referral.sock;
    }

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

# configuration file /etc/nginx/proxy_params:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;


FIXED: my domestic_voicelogging css where i get the image that path was wrong this is the correct path:

background-image: url('/domestic_voicelogging/static/images/Login.png');