Static content seems to load with a 404 error... uwsgi nginx

73 views
Skip to first unread message

Encompass solutions

unread,
Oct 4, 2015, 6:24:03 AM10/4/15
to web2py-users
I have setup uwsgi and I seem to be very close to having everything working.
It just seems that my static data is not loaded now. (css, images, so forth)
This is my nginx file with the web2py applicaiton in it.
Any ideas into the issue?  My web2py installation is located in /var/www/web2py/.
# file /etc/nginx/sites-available/web2py
server {
        listen          80;
        server_name     $hostname;
        #to enable correct use of response.static_version
        #location ~* /(\w+)/static(?:/_[\d]+.[\d]+.[\d]+)?/(.*)$ {
        #    alias /home/www-data/web2py/applications/$1/static/$2;
        #    expires max;
        #}
        location ~* /(\w+)/static/ {
            root /home/www-data/web2py/applications/;
            #remove next comment on production
            #expires max;
        }
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.sock;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
        }
}
server {
        listen 443 default_server ssl;
        server_name     $hostname;
        ssl_certificate         /etc/nginx/ssl/web2py.crt;
        ssl_certificate_key     /etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
        ssl_protocols SSLv3 TLSv1;
        keepalive_timeout    70;
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.sock;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
        }

}



Anthony

unread,
Oct 4, 2015, 9:28:09 AM10/4/15
to web2py-users
        location ~* /(\w+)/static/ {
            root
/home/www-data/web2py/applications/;

should be:

        location ~* /(\w+)/static/ {
            root
/var/www/web2py/applications/;

Also, you'll need to repeat that configuration in the SSL section if you want nginx to serve static files via HTTPS as well.

Anthony

Encompass solutions

unread,
Oct 4, 2015, 12:43:27 PM10/4/15
to web2py-users
Goodness me... How did I miss that!
And doesn't seem to be working in my server section for ssl... here is the adapted, section:
I assume the "location" should be before / is that right?  Does it make a difference?
server {
        listen 443 default_server ssl;
        server_name     $hostname;
        ssl_certificate         /etc/nginx/ssl/web2py.crt;
        ssl_certificate_key     /etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS$
        ssl_protocols SSLv3 TLSv1;
        keepalive_timeout    70;
        location ~* /(\w+)/static/ {
            root /var/www/web2py/applications/;
        }
        location / {

Encompass solutions

unread,
Oct 5, 2015, 1:20:14 PM10/5/15
to web2py-users
Ok for reference.  I got it working.
Here is the final outcome of my web2py nginx settings file.


#file /etc/nginx/sites-available/web2py
server {
        listen          80;
        server_name     $hostname;
        #to enable correct use of response.static_version
        #location ~* /(\w+)/static(?:/_[\d]+.[\d]+.[\d]+)?/(.*)$ {
        #    alias /home/www-data/web2py/applications/$1/static/$2;
        #    expires max;
        #}
        location ~* /(\w+)/static/ {
            root /var/www/web2py/applications/;
        }
        location / {
            uwsgi_pass      unix:///tmp/web2py.sock;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
        }
}
server {
        listen          443 default_server ssl;
        server_name     $hostname;
        ssl_certificate         /etc/nginx/ssl/web2py.crt;
        ssl_certificate_key     /etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
        ssl_protocols SSLv3 TLSv1;
        keepalive_timeout    70;
        location / {
            uwsgi_pass      unix:///tmp/web2py.sock;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
        }

}


On Sunday, October 4, 2015 at 1:24:03 PM UTC+3, Encompass solutions wrote:
Reply all
Reply to author
Forward
0 new messages