views:

53

answers:

3

How to configure nginx for load static ? Static should be given only by the nginx server , everything else nginx + dev_appserver and workingon the same host (localhost or localhost: port)

Example
    request html
    http://localhost -> nginx -> dev_appserver

    request static files 
    http://localhost/static/css (js,img,etc) -> nginx
+1  A: 

the best is define a rules to do that with testing id $request_filename exist or not in your filesystem with -f test. like that

if (-f $request_filename)

An exemple can be like that

upstream my_server {
        server 127.0.0.1:44000;
        server 127.0.0.1:44001;
}
server {
        listen      80;

            if (-f $request_filename) {
                expires      max;
                break;
            }
            if (!-f $request_filename){ 
                proxy_pass  http://my_server;
            }
}
shingara
A: 

What's the point? You won't be able to deploy nginx with your app in production - GAE doesn't allow it. So why bother about it during local development?

sri
+1  A: 

Using if is strongly discouraged by Nginx author Igor Sysoev, especially for testing file existance. To provide some means to achieve this kind of tasks he introduced try_files directive

server {
  listen 80;

  root /var/your/gae/project/root;

  location / {
    try_files $uri @gae;
  }

  location @gae {
    proxy_pass http://gae;
  }
}

The arguments to try_files is a list of file patterns (you can use variables, as in our example) to test for existance (e.g. you could test $uri $uri.html $uri.htm in turn) and the last argument is a named location Nginx makes a redirect to if no exisiting file found.

Alexander Azarov