Search code examples
nginxvhostshosts-file

Nginx starts and stops too slowly (15 seconds delay)


I found at that for some reason running nginx on command line (same for nginx -s stop etc.) takes quite a long time, over 15 seconds to complete. Yet there seems to be no errors or warnings of any kind.

Also, once the server starts, it seems to work normally.

What could be causing this slow load times?

Running on MacOS X.


Solution

  • I found that this particular line of config was slowing the load:

    server {
        listen 8080;
        server_name example.com;
    
        location /specialpath/ {
            proxy_buffering off;
            proxy_set_header Host example.com:8080;
            proxy_pass http://example.com:8000/specialpath/;  # THIS LINE
        }
    ...
    }
    

    Changing this:

    proxy_pass http://example.com:8000/specialpath/;
    

    ... to this:

    proxy_pass http://localhost:8000/specialpath/;
    

    ... has completely resolved the starting lag.

    Of course, example.com was mapped to 127.0.0.1 in /etc/hosts file all the while.