static files does not load at all

I’ve deployed my django project “django_chatbot” on an ubuntu server on Digitalocean. the user is “aras”, and the project folder is:
“/home/aras/django_chatbot”

In the settings.py file, I changed these lines:

ALLOWED_HOSTS = ['64.227.102.100']
STATIC_URL = '/static/'
STATIC_ROOT =  '/var/www/my_project/static/'

With “sudo nano /etc/nginx/sites-available/django_chatbot” I’ve edited Nginx configuration :

server {
    listen 80;
    server_name 64.227.102.100;

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

    location /static/ {
        alias /var/www/my_project/static/;
    }

    location / {
        include proxy_params;
        # Adjust this line for your .sock file
        proxy_pass http://unix:/home/aras/django_chatbot/django_chatbot.sock;
    }
{

After deploying this project on the server by this command:

gunicorn --bind 64.227.102.100:8000 django_chatbot.wsgi

my static files do not load on the website.
My nginx log is:

[error] 32978#32978: *350 open() "/var/www/my_project/static/historypage.js" failed (2: No such file or directory), client: 185.180.140.141, server: 64.227.102.100, request: "GET /static/historypage.js HTTP/1.1", host: "64.227.102.100"
2023/08/29 04:09:07 [notice] 42213#42213: signal process started
2023/08/29 04:43:23 [notice] 42607#42607: signal process started
2023/08/29 04:43:23 [notice] 42613#42613: signal process started
2023/08/29 04:43:23 [notice] 42618#42618: signal process started
2023/08/29 04:43:23 [notice] 42624#42624: signal process started
2023/08/29 06:45:24 [notice] 43969#43969: signal process started
2023/08/29 06:57:16 [notice] 44086#44086: signal process started

Can any body help me?
Thanks in advane

Have you verified that that static file is in that directory?

Did you run collectstatic to copy the files there?

Does nginx have the appropriate access to those directories and files?

1 Like

Did you run collectstatic to copy the files there?

Yes,

Does nginx have the appropriate access to those directories and files?

I’ve prepared nginx access for the “static” folder at: /var/www/my_project/static/
but not for the sub folders and files within that.
It it necessary?

In the nginx log, I wonder about historypage.js failure to load. because i do not have such file in my static folder of my app. And the log does not cover other failure of logo and fonts.

Check the permissions. I don’t know what accounts you’re using or how you’re running your deployment process.

1 Like

What url are you using to access your site?

What url are you using to access your site?

64.227.102.106:8000

So you’re bypassing nginx - or trying to anyway.

Your nginx configuration has:

which means you should be accessing your site on port 80. (http)

Thanks Ken,
Then what should I do to make it correct?

Access your site on port 80, not 8000.

Access your site on port 80, not 8000.

I’m sorry Ken, but you mean I have to run:

gunicorn --bind 64.227.102.106:80 django_chatbot.wsgi

?

No. In your browser, when you go to the web site.
Go to port 80 on the server, not 8000.

Go to port 80 on the server, not 8000.

you mean I run:
gunicorn --bind 64.227.102.106:8000 django_chatbot.wsgi
but go to this IP to visit website?
http://64.227.102.106

Yes. Do not change any of your configuration (yet). Only change the url you enter in your browser.

OK,
Now it is running, but cannot accessible without :8000 at the end of it.

What do you mean? Provide more details about what you’re seeing, both in your browser and on the server.

on server:

gunicorn --bind 64.227.102.106:8000 django_chatbot.wsgi
[2023-08-30 03:18:31 +0000] [51021] [INFO] Starting gunicorn 21.2.0
[2023-08-30 03:18:31 +0000] [51021] [INFO] Listening at: http://64.227.102.106:8000 (51021)
[2023-08-30 03:18:31 +0000] [51021] [INFO] Using worker: sync
[2023-08-30 03:18:31 +0000] [51022] [INFO] Booting worker with pid: 51022

on browser:

What about your nginx log?

sudo tail -f /var/log/nginx/access.log
104.43.161.68 - - [30/Aug/2023:03:18:15 +0000] "GET /shop/wp-includes/wlwmanifest.xml HTTP/1.1" 404 564 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
104.43.161.68 - - [30/Aug/2023:03:18:16 +0000] "GET /wp1/wp-includes/wlwmanifest.xml HTTP/1.1" 404 564 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
104.43.161.68 - - [30/Aug/2023:03:18:16 +0000] "GET /test/wp-includes/wlwmanifest.xml HTTP/1.1" 404 564 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
104.43.161.68 - - [30/Aug/2023:03:18:16 +0000] "GET /site/wp-includes/wlwmanifest.xml HTTP/1.1" 404 564 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
104.43.161.68 - - [30/Aug/2023:03:18:17 +0000] "GET /cms/wp-includes/wlwmanifest.xml HTTP/1.1" 404 564 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
104.43.161.68 - - [30/Aug/2023:03:18:17 +0000] "" 400 0 "-" "-"
4.17.224.131 - - [30/Aug/2023:03:33:35 +0000] "GET /laravel/.env HTTP/1.1" 404 159 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
4.17.224.131 - - [30/Aug/2023:03:33:35 +0000] "POST /laravel HTTP/1.1" 404 159 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
107.170.232.21 - - [30/Aug/2023:03:46:46 +0000] "GET / HTTP/1.1" 200 712 "-" "Mozilla/5.0 zgrab/0.x"
45.79.128.205 - - [30/Aug/2023:03:51:15 +0000] "\x16\x03\x01\x00\x85\x01\x00\x00\x81\x03\x03\xD5\x99\xA3l\xA5\x0Cag!5.\x8DQ\x912\xE4-\x80\x9C\xBC\xCE\x9DGL\xA2e\x10\xAA\x7F\x05\x01*\x00\x00 \xC0/\xC00\xC0+\xC0,\xCC\xA8\xCC\xA9\xC0\x13\xC0\x09\xC0\x14\xC0" 400 166 "-" "-"

What about your error log? (Note, it may be helpful to filter your logs by only displaying lines with your ip address to screen out all the bot traffic.)