0

The stack is: Ubuntu // Supervisor // Nginx <--> Gunicorn <--> Django 1.11

Static files folder: /home/sitebiz/sitebiz/static/

Nginx config: /etc/nginx/sites-enabled/site.biz

server {
        listen   80;
        listen   [::]:80;
        access_log off;
        server_name site.biz;
        return 301 https://$server_name$request_uri;
}


server {
    listen              443 ssl;
    #listen              80 ssl;
    server_name         site.biz;
    ssl_certificate     /etc/letsencrypt/live/site.biz/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/site.biz/privkey.pem;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    #listen 80;

    gzip on;
    access_log /var/log/nginx-access.log;
    error_log /var/log/nginx-error.log;


    location /static {
        root  /home/sitebiz/sitebiz;
        internal;
    }

    location /track {
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
        proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://127.0.0.1:8899;
            break;
        }
    }

    location /income {
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
        proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://127.0.0.1:8899;
            break;
        }
    }


    location / {
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
        proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://127.0.0.1:8000;
            break;
        }
    }
}        

I tried to change the /home/sitebiz/sitebiz/static/ directory and all of its content ownership to sitebiz user and to www-data , but none helped. Not even Django itself can serve static files and I have no idea why.

From django settings:

SITE_ROOT = os.path.abspath(os.path.dirname(name)) 
MEDIA_URL = '/media/' 
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 
STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(SITE_ROOT, 'static') 

Thank you in advance.

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
Artem Bulatov
  • 123
  • 3
  • 7
  • 1
    `root /sitebiz/sitebiz;` this does not lead to `/home/` – Ivan Starostin Aug 24 '18 at 12:00
  • Sorry, I don't know, why it was mangled here. The block is **location /static/ { root /home/sitebiz/sitebiz; internal; }** – Artem Bulatov Aug 24 '18 at 12:14
  • Is there an entry in the `nginx` error log? Also, does the `nginx` worker username have read access to all of the directories above `/home/sitebiz/sitebiz/static/`? – Richard Smith Aug 24 '18 at 12:24
  • In the **Project** directory: **drwxr-xr-x 18 sitebiz sitebiz 4096 Aug 23 17:32 static** In the **static** directory drwxr-xr-x 16 sitebiz sitebiz 4096 Aug 23 17:57 .. drwxr-xr-x 6 sitebiz sitebiz 4096 Aug 23 17:30 admin drwxr-xr-x 2 sitebiz sitebiz 4096 Aug 23 17:32 angular drwxr-xr-x 6 sitebiz sitebiz 4096 Aug 23 17:32 bootstrap .... and so on ........ – Artem Bulatov Aug 24 '18 at 12:30
  • 1
    location /static {} remove slash – Marin Aug 24 '18 at 12:39
  • @marin , thank you, but unfortunately it did not help – Artem Bulatov Aug 24 '18 at 12:47
  • Did you run `collectstatic`? What does your `STATIC_ROOT` look like in your settings.py in your Django project? – Scott Skiles Aug 24 '18 at 12:50
  • @ScottSkiles, **SITE_ROOT** = os.path.abspath(os.path.dirname(__name__)) **MEDIA_URL** = '/media/' **MEDIA_ROOT** = os.path.join(BASE_DIR, 'media') **STATIC_URL** = '/static/' **STATIC_ROOT** = os.path.join(SITE_ROOT, 'static') – Artem Bulatov Aug 24 '18 at 12:56
  • 1
    Did `collectstatic` work? 403 error is forbidden. You might need to `chown` the directory you want to collect the static files into, collect them, then `chown` it back. Also, Fabric is helpful for this stuff if this is indeed the issue: http://www.fabfile.org/ – Scott Skiles Aug 24 '18 at 12:59
  • can you show your django settings, and URL-s – Marin Aug 24 '18 at 13:09
  • @ScottSkiles, no, unfortunately, does not work. I tried chowning to **www-data** and back to **sitebiz** user. – Artem Bulatov Aug 24 '18 at 13:44
  • @marin, can settings file help if Nginx is the one that serves the files in /static directory? – Artem Bulatov Aug 24 '18 at 13:50
  • @gencurrent can you share URL of static file you are trying to access? And actual path to that file. – Ivan Starostin Aug 24 '18 at 14:43
  • @IvanStarostin, /home/sitebiz/sitebiz/static – Artem Bulatov Aug 24 '18 at 16:41
  • ...is that a file path or a file URL? Or you are trying to view static directory in browser? @gencurrent – Ivan Starostin Aug 24 '18 at 17:02

1 Answers1

0

I have no idea, why, but the solution from the POST works fine

Just execute in shell:

sudo chmod o+x /root

If someone could explain this logic - why root folder must have Execute permission - I would be very thankful (and upvoteful)

Artem Bulatov
  • 123
  • 3
  • 7