0

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";
Ian
  • 101
  • 1
  • Is `myapp.com`, `a.myapp.com` and `b.myapp.com` all running on the same `nginx` server? – Richard Smith Oct 14 '17 at 21:59
  • You could check with lsof (list open files), probably need to install it as most linux distro's don't include this by default. It should give you a view on which ones those open files are and the processes that own it (so you can grep for php). do a lsof | wc -l to count those. Are there really that much open ? Or perhaps the error is more like a symptom of something deeper. – Ilham Sulaksono Oct 14 '17 at 23:10
  • @RichardSmith yes, all on the same nginx. – Ian Oct 16 '17 at 12:21
  • @IlhamSulaksono no, not that much php files open. Greping by nginx or .conf doesn't show much files either. – Ian Oct 16 '17 at 12:26
  • In that case, setting `Host` to `$host` would just point it back to itself. – Richard Smith Oct 16 '17 at 13:04

0 Answers0