0

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?

1
  • 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. Jun 18, 2011 at 21:59

1 Answer 1

1
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

2
  • That's not going to do redirection, forwarding on any have much overhead right?
    – user80666
    Jun 18, 2011 at 20:39
  • I actually just tested it and it does not work.
    – user80666
    Jun 18, 2011 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .