0

So I have this problem with deploying static files on server with Django. I am running nginx, and successfully tested my website locally, but now, when I'm deploying my site on the web, I can't load the local files, despite I have done everything according to the instructions. So I got this error all the time

"GET /staticold/botadd/anyfile HTTP/1.0" 404 99

My settings.py static settings looks like this

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

I've also tried it like this

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

python manage.py collectfiles command is successfull, all of my files are transfered to STATIC_ROOT folder, but then I got that 404 error. What can it be, I am stuck.

My sites-available/default

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            proxy_pass http://localhost:8000;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #       include snippets/fastcgi-php.conf;
    #
    #       # With php7.0-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    #       # With php7.0-fpm:
    #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #       deny all;
    #}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

1 Answers1

0

You may have to tell nginx where to look to serve your static content. Try adding a "location /static/" block in your nginx sites-available file, eg:

server {
    server_name <your_server_name>.com;
    listen 443;
    listen [::]:443;

    ssl on;
    ssl_certificate /etc/nginx/ssl/cert.crt;
    ssl_certificate_key /etc/nginx/ssl/private.key;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        allow all;
        alias /your/base/dir/here/.../botadd/static/;
    }
    location / {
        ...
    }
}
dsaves
  • 181
  • 8