I have the following .conf in nginx to balance between server a and b:
upstream myapp {
server a.myapp.com;
server b.myapp.com;
}
server {
listen 80;
server_name myapp.com;
location / {
proxy_pass http://myapp;
}
}
And two servers with php 7 and laravel running my app, inside the same nginx.
With this config, the Host header becomes "myapp" and laravel uses it in some URL system for assets and links.
As described in docs, I used the proxy_set_header
directive like so:
upstream myapp {
server a.myapp.com;
server b.myapp.com;
}
server {
listen 80;
server_name myapp.com;
location / {
proxy_pass http://myapp;
proxy_set_header Host $host; #this causes too many open files
}
}
But it causes "too many open files" on nginx log, and requests never finish.
I googled the "too many open files" error and came up with the increase limit solution, wich obviosly did not work in this case. Maybe there is some infinite loop that I am not seeing?
I also tried to write the Host header inside each app .conf, but the header is not written in any of this ways:
fastcgi_pass_header "Host myapp.com";
proxy_set_header Host "myapp.com";
add_header Host "myapp.com";