Location conflict to serve static homepage
September 17, 2009 11:01AM
Hello!

I have a high-load website running Nginx for static files and Apache+Django for dynamic requests.

I want to serve the homepage from a static file instead of passing the request to Apache, but Nginx always matches the location directive for dynamic requests.

Here is a part of my setup:

[code]
# Serve static index.html on default root for the homepage
location = / {
break;
}
# Proxy other requests to Apache
location / {
proxy_pass http://127.0.0.1:8888;
proxy_redirect off;
}
[/code]
Re: Location conflict to serve static homepage
September 17, 2009 01:07PM
You can use a "try_files" directive - see http://wiki.nginx.org/NginxHttpMainModule#try_files.

Something like this might work:

[code]
location / {
index index.html; #probably redundant
try_files $uri $uri/ @django;
}

location @django {
proxy_pass http://127.0.0.1:8888;
proxy_redirect off;
....
}
[/code]

This requires a recent version of nginx (0.6.36+, 0.7.27+, 0.8.x). What this *should* do is that nginx will try the URI first. If it's a directory, it will look for an index file in that directory. If there are no matches if will pass to the backend.

--
Jim Ohlstein
Re: Location conflict to serve static homepage
September 17, 2009 01:22PM
Hello Jim!

I'll have to install a more recent version of Nginx, mine is from the stable Debian repo (version 0.6.32).

Thanks for the tip.

Best regards,
Enrico
Re: Location conflict to serve static homepage
September 17, 2009 02:12PM
Hello!

I've updated nginx using instructions from here:
http://www.ruby-forum.com/topic/194069

Now I used your suggestion and it's working!

Thanks!
Re: Location conflict to serve static homepage
September 17, 2009 02:14PM
That's great. Glad I could help.

--
Jim Ohlstein
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 268
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready