# MySQL and Nginx mystery

**URL:** <https://www.ruby-forum.com/t/mysql-and-nginx-mystery/206667>\
**Category:** NGINX\
**Created:** [May 6, 2011, 8:53pm UTC](https://www.ruby-forum.com/t/mysql-and-nginx-mystery/206667 "2011-05-06T20:53:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 6, 2011, 8:53pm UTC](https://www.ruby-forum.com/t/mysql-and-nginx-mystery/206667/1 "2011-05-06T20:53:26Z")

</div>

Hi all,

I have set a fastcgi upstream into Nginx configuration:

upstream fastcgi {  
ip\_hash;  
server 192.168.0.2:9000;  
server 192.168.0.3:9000;  
server 192.168.0.4:9000;  
}

Everything works perfect, except when I try to connect to MySQL, using  
PHP.

$server = ‘192.168.0.40’;  
$username = ‘tester’;  
$password = ‘password’;  
mysql\_connect($server, $username, $password);

I get a connection error telling me that I cannot connect to MySQL using  
192.168.0.2!  
(or whatever server I’m on it at that specific moment)

Current setup:  
3 web servers, 2 set with heartbeat, nginx as start service  
2 db servers, set with heartbeat and DRBD, mysqld as start service

Is there a header that I need to set into Nginx or this is a network  
configuration issue that I need to alert the host guys about?  
I did set the bind-address in my.cnf to 192.168.0.40 ip.

Thanks for your help.

Posted at Nginx Forum:

> **[MySQL and Nginx mystery](https://forum.nginx.org/read.php?2,196165,196165#msg-196165)**
>
> Hi all, I have set a fastcgi upstream into Nginx configuration: upstream fastcgi { ip\_hash; server 192.168.0.2:9000; server 192.168.0.3:9000; server 192.168.0.4:9000; } Everything works perfect, except wh

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [May 6, 2011, 9:50pm UTC](https://www.ruby-forum.com/t/mysql-and-nginx-mystery/206667/2 "2011-05-06T21:50:55Z")

</div>

What I actually try to do is: force Nginx to show one IP to the MySQL  
server, no matter on what server the user is.

Posted at Nginx Forum:

> **[Re: MySQL and Nginx mystery](https://forum.nginx.org/read.php?2,196165,196181#msg-196181)**
>
> Hi all, I have set a fastcgi upstream into Nginx configuration: upstream fastcgi { ip\_hash; server 192.168.0.2:9000; server 192.168.0.3:9000; server 192.168.0.4:9000; } Everything works perfect, except wh

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [May 6, 2011, 11:06pm UTC](https://www.ruby-forum.com/t/mysql-and-nginx-mystery/206667/3 "2011-05-06T23:06:50Z")

</div>

On Fri, May 06, 2011 at 03:50:08PM -0400, TECK wrote:

Hi there,

> What I actually try to do is: force Nginx to show one IP to the MySQL  
> server, no matter on what server the user is.

In your setup, nginx isn’t talking to mysql at all.

It’s the fastcgi server that runs the php code that connects to mysql.  
So  
you’ll want to look there for the resolution.

Good luck,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
