# Nginx as load balancer + apache as a web server issue

**URL:** <https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031>\
**Category:** NGINX\
**Created:** [August 10, 2010, 9:25am UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031 "2010-08-10T09:25:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 10, 2010, 9:25am UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/1 "2010-08-10T09:25:03Z")

</div>

Hello guys,

Im having some weird issue. I currently have my website setup as  
follows,

- 1 nginx server configured as a load balancer
- 2 apache servers configured to server the http traffic from the nginx  
server

I have a similar ecommerce site where people can buy products, the issue  
is that when I try to remove a product from the cart, the product doesnt  
get removed.

Few troubleshooting achievements that inclined me to say that its nginx:  
I changed my local DNS so I mapped my website to use each of my apache  
web servers directly and the problem doesnt show up! item gets removed  
from the cart properly.

This is a HTTP website, no secure connection are enabled yet. Could this  
be because of a PHP session issues? I have “ip\_hash;” configured on my  
nginx.conf config file. I can paste my nginx.conf if needed.

Any advice will be appreciated!

Thank you.

Posted at Nginx Forum:

> **[nginx as load balancer + apache as a web server issue](https://forum.nginx.org/read.php?2,118156,118156#msg-118156)**
>
> Hello guys, Im having some weird issue. I currently have my website setup as follows, - 1 nginx server configured as a load balancer - 2 apache servers configured to server the http traffic from the nginx server I have a similar ecommerce site wher

---

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 10, 2010, 9:35am UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/2 "2010-08-10T09:35:00Z")

</div>

sounds to me like a session issue. why not just use memcached as session  
backend?

[http://www.dotdeb.org/2008/08/25/storing-your-php-sessions-using-memcached/](http://www.dotdeb.org/2008/08/25/storing-your-php-sessions-using-memcached/)

---

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 10, 2010, 8:47pm UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/3 "2010-08-10T20:47:13Z")

</div>

Hello,

Thanks for your quick response, Im going to try that now.  
The thing is I have two webservers, on which one should I store this? If  
Im not wrong if the server that has the memcache running goes down my  
website will wont work, is that correct?

Thanks again.

Posted at Nginx Forum:

> **[Re: nginx as load balancer + apache as a web server issue](https://forum.nginx.org/read.php?2,118156,118402#msg-118402)**
>
> Hello guys, Im having some weird issue. I currently have my website setup as follows, - 1 nginx server configured as a load balancer - 2 apache servers configured to server the http traffic from the nginx server I have a similar ecommerce site wher

---

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 10, 2010, 9:23pm UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/4 "2010-08-10T21:23:32Z")

</div>

> Thanks for your quick response, Im going to try that now.  
> The thing is I have two webservers, on which one should I store this? If  
> Im not wrong if the server that has the memcache running goes down my  
> website will wont work, is that correct?

You can run a memcached instance on each webserver and provide both to  
the  
php client/extension. It will automatically distribute / loadbalance and  
in  
case one server goes down continue to work with other (typically all  
memcache extensions disable the failed instance for given time period  
(15  
secs) and retry later so there is bassically also no connect delays  
because  
of unresponding servers).

Depending on the needs there is possibility to replicate the session  
data  
(sessions are written to both memcache servers) by setting the PHP ini  
variable memcache.session\_redundancy for example to 2.

rr

---

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 11, 2010, 12:12am UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/5 "2010-08-11T00:12:43Z")

</div>

Hello again,

Another troubleshooting achievement, Its working on firefox with or  
without doing the memcache config just fine. It seems the problem is on  
ie8 only. Although when I use ie8 with the local DNS mapping explaine  
above Im not getting such a weird problem.

Posted at Nginx Forum:

> **[Re: nginx as load balancer + apache as a web server issue](https://forum.nginx.org/read.php?2,118156,118490#msg-118490)**
>
> Hello guys, Im having some weird issue. I currently have my website setup as follows, - 1 nginx server configured as a load balancer - 2 apache servers configured to server the http traffic from the nginx server I have a similar ecommerce site wher

---

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 11, 2010, 3:18am UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/6 "2010-08-11T03:18:16Z")

</div>

Hey guys,

I have just found and fixed the issue, it was related to the following  
settings, commenting them solved the ie8 issue,

# client\_body\_timeout 60;

# client\_header\_timeout 60;

# expires 24h;

# keepalive\_timeout 60 60;

# send\_timeout 60;

Any advice why this would happen?

Thanks!

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,118156,118569#msg-118569](http://forum.nginx.org/read.php?2,118156,118569#msg-118569)

---

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 11, 2010, 11:48pm UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/7 "2010-08-11T23:48:47Z")

</div>

On Tue, Aug 10, 2010 at 8:17 PM, josesan311 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Any advice why this would happen?

The “expires 24h” is probably telling nginx to add a cache-control  
header to everything in that location. So the browser was caching the  
old page that didn’t have the item removed from the cart, and showing  
that. (I am assuming your “expires” was set at a high level in nginx  
configuration, maybe at the server level?)

Typically, in most applications, dynamic pages should expire  
immediately, and static items (images, CSS, JS, etc.) should have  
longer expiration times sent to the browser. (There are exceptions, of  
course… think of an RSS feed. You might want it to be cached for 15  
minutes, even though it is a dymic page.)

You can make separate locations in nginx to fix this (one for statics,  
the other for dynamics). Use a regex-based location if all the dynamic  
stuff isn’t under one path.

–  
RPM

---

<div class="post-metadata">

**Author:** ![josesan311](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c37758/32.png) [@josesan311](https://www.ruby-forum.com/u/josesan311)\
**Post date:** [August 10, 2010, 11:56pm UTC](https://www.ruby-forum.com/t/nginx-as-load-balancer-apache-as-a-web-server-issue/193031/8 "2010-08-10T23:56:54Z")

</div>

Hey guys,

I have just put one of the webserver nodes down in nginx.conf and  
installed memcached+PHP memcache on the only running apache webserver,  
although the problem persists.

Any advice?

Posted at Nginx Forum:

> **[Re: nginx as load balancer + apache as a web server issue](https://forum.nginx.org/read.php?2,118156,118478#msg-118478)**
>
> Hello guys, Im having some weird issue. I currently have my website setup as follows, - 1 nginx server configured as a load balancer - 2 apache servers configured to server the http traffic from the nginx server I have a similar ecommerce site wher
