Welcome! Log In Create A New Profile

Advanced

nginx to nginx proxy_pass and upstream

Posted by gigikent2000 
nginx to nginx proxy_pass and upstream
June 13, 2011 04:06PM
Hi guys,

I have several high profile php sites and i want to load balance them onto 3 (or more) web servers stored on virtual machines on top of vCenter.

I want to easily give more perfomance to all sites in case i need, just by adding another drone virtual machine to the setup.
I have

1) Front end web server (nginx 1.02) with upstream to main and second


2) main.website.com (nginx 1.02)
3) second.website.com (nginx 1.02)

main and second website.com host all theese websites which are replicated between them. main and second run nginx with apc and php-fpm

the setup works perfectly for the first website (with upstream and proxy_pass to second website). Unfortunatelly, for the second website, it just returns the first website (HTTP 1.0 for upstream ? but not for proxy_pass ?). The strange fact is that, when i use proxy_pass directly to the vhost it runs perfectly.


The conf is the following:

1) upstream rra {
server main.website1.ro max_fails=3 fail_timeout=30s;
server apps1.website1.local max_fails=3 fail_timeout=30s weight=5;
}
location / {
proxy_cache two;

proxy_cache_valid 200 302 2m;

proxy_cache_valid 404 1m;

proxy_cache_valid any 1m;
proxy_cache_key "rrai$request_uri";

gzip on;
gzip_http_version 1.1;
gzip_vary on;
expires 1m;

proxy_pass http://rra;


this is the first website which works, for the second website nope

Any ideas ?

Vlad
Re: nginx to nginx proxy_pass and upstream
June 13, 2011 05:46PM
HI!

Try adding the following to your config:
proxy_set_header Host $http_host;

You're current config is not passing back the original users http_host header, so you're backend config leveraging the default vhost. Enabling the above config line will maintain the original header through the proxy_pass and allow your backend vhosts to react accordingly.

There are a number of other proxy_pass options that might also be helpful:


proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Good luck!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 174
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