Home > Mobile >  nginx not serving statick files django 4.1
nginx not serving statick files django 4.1

Time:10-03

i am new in deploy projects my static files not serving with nginx

thats look my site-available/myprject file

server{
    listen 80;
    server_name mydomain;

    location = /favicon.ico { access_log off; log_not_found off; }
    
    location /static/ {
    autoindex on;
    alias /home/user/project/static;
    }
    
    location /media/ {
    autoindex on;
    alias /home/user/project/media;
    }

    location / {
     proxy_pass myIp:myPort;

    }
}

my static files and media have this path

/home/user/project/staict files and media files

that's how it looks my settings.py configurations

STATIC_URL = '/static/'
STATIC_ROOT =os.path.join(BASE_DIR,'static')

my debug variable is false

i run collectstatic

thanks for any answers.

CodePudding user response:

Try the following in your settings.py:

STATIC_URL = '/staticfiles/'
STATIC_ROOT = str(BASE_DIR.joinpath('staticfiles'))
STATICFILES_DIRS = [str(BASE_DIR.joinpath('static'))]

CodePudding user response:

Here is what I see that this different from my working Django site:

    server_name mydomain;```
should be->

```listen 80;
    server_name myIP;```

```alias /home/user/project/static;``` 
should be ->

```alias /home/user/project/static/;```

```location / {
     proxy_pass myIp:myPort;``` 
should be ->

```locatinon /{ 
      include        proxy_params;
      proxy_pass     http://myIp:myPort; ```

then

```STATIC_URL = '/static/'
STATIC_ROOT =os.path.join(BASE_DIR,'static')```
should be ->

```STATIC_URL = '/static/'
   STATIC_ROOT = /home/user/project/static;
   STATICFIES_DIRS = [os.path.join(BASE_DIR, 'static/'),
   ]```

  • Related