Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving static homepage with nginx and rest through uwsgi

Tags:

nginx

flask

uwsgi

I have a nginx + uwsgi website (using Flask for dynamic python pages). I would like to serve the homepage which is static directly through nginx and route everything else to uwsgi.

The following nginx configuration directives work well to serve the homepage through nginx and redirect a call to mysite.com/login to uwsgi:

location / {                                                                                                                                                                                                
    root  /var/www/mysite.com/static;                                                                                                                                                                
    index  index.html index.htm;                                                                                                                                                                            
}                                                                                                                                                                                                           

location /login {                                                                                                                                                                                           
    include uwsgi_params;                                                                                                                                                                                   
    uwsgi_pass 127.0.0.1:3031;                                                                                                                                                                              
} 

But I can't find a way to generalize the second directive to catch all calls to mysite.com/something and direct them to uwsgi.

I tried the following which didn't work (get 404 for anything except calls to mysite.com):

location / {                                                                                                                                                                                                
    root  /var/www/mysite.com/static;                                                                                                                                                                
    index  index.html index.htm;                                                                                                                                                                            
}                                                                                                                                                                                                           

location /* {                                                                                                                                                                                           
    include uwsgi_params;                                                                                                                                                                                   
    uwsgi_pass 127.0.0.1:3031;                                                                                                                                                                              
}

Any suggestions?

like image 267
gws Avatar asked Dec 24 '11 14:12

gws


1 Answers

Try something like this

server {
...
 root  /var/www/mysite.com/static;                                                                                                                                                                
 index  index.html index.htm;   
 try_files $uri @uwsgi; 
 location @uwsgi{
    include uwsgi_params;                                                                                                                                                                                   
    uwsgi_pass 127.0.0.1:3031; 
 }
...
}

http://wiki.nginx.org/HttpCoreModule#try_files

like image 91
Marcelo Bittencourt Avatar answered Oct 16 '22 13:10

Marcelo Bittencourt