Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a NginX vhost, where all static content is served by nginx and anything that's not found or ends with php proxies to apache.

Just wanted to check if I have locations right:

location / {
  try_files $uri $uri/ @proxy;
  expires 30d;
}

location ~* \.php$ {
   proxy_pass      http://127.0.0.1:8080;
} 

location @proxy {
   proxy_pass      http://127.0.0.1:8080;
}

I was also wondering if there is a way to make second location go to third so that I do not have to repeat the proxy_pass line twice?

I have few other questions:

  • Does nginx read locations from top to bottom and does it stop looking at next location if curent request matches one of the locations? For example, if server.com/image.jpg is requested, does it mean the very first location declaration will capture it in my locations, and rest will be ignored?

  • If I do expires max; or expires 30d; but then site is updated and I want to force user browsers to reload the file right away, is there anything I can do to make them reload?

  • my very first location declaration will match anypath that ends with .js, .css, .png and so on, but is it case sensitive? will it also match .PNG ? Should I make it case sensitive or not? If yes, how?

  • Is there anything else you think would improve this configuration?

share|improve this question
1  
Many of your questions can be answered just by reading the documentation at: wiki.nginx.org/HttpCoreModule#location . You cannot make location 2 go to location 3, but you can use an upstream block to prevent repetition of the ip address. –  Martin Fjordvald Jun 18 '11 at 21:59
    
@martin-f, thank you. –  user80666 Jun 18 '11 at 23:47
add comment

1 Answer

location / {
  try_files $uri $uri/ @proxy;
  expires 30d;
}

location ~* \.php$ {
   root @proxy;
} 

location @proxy {
   proxy_pass      http://127.0.0.1:8080;
}

Should do it

share|improve this answer
    
That's not going to do redirection, forwarding on any have much overhead right? –  user80666 Jun 18 '11 at 20:39
    
I actually just tested it and it does not work. –  user80666 Jun 18 '11 at 20:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.