connect() failed (111: Connection refused) while connecting to upstream

It sounds like you haven’t started and configured the backend for Nginx. Start php-fpm and add the following to nginx.conf, in the http context: server { listen 127.0.0.1; server_name localhost; error_log /var/log/nginx/localhost.error_log info; root /var/www/localhost/htdocs; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; fastcgi_intercept_errors on; error_page 404 /error/404.php; } }

Make nginx to pass hostname of the upstream when reverseproxying

Actually you can do that via proxy_set_header. For more details look here: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header or see an example use-case here: https://stackoverflow.com/questions/12847771/configure-nginx-with-proxy-pass I have included the dynamic approach into your above posted configuration: server { listen 80; server_name example.com; location / { proxy_pass http://main; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } } Here is an example with … Read more

How to output variable in nginx log for debugging

You can send nginx variable values via headers. Handy for development. add_header X-uri “$uri”; and you’ll see in your browser’s response headers: X-uri:/index.php I sometimes do this during local development. It’s also handy for telling you if a subsection is getting executed or not. Just sprinkle it inside your clauses to see if they’re getting … Read more

Nginx enable site command

If you have installed the nginx package from the Ubuntu repositories, you will have two directories. /etc/nginx/sites-enabled and /etc/nginx/sites-available. In the main nginx configuration, /etc/nginx/nginx.conf, you have the following line: include /etc/nginx/sites-enabled/*.conf; So basically to list all available virtualhosts, you can run the following command: ls /etc/nginx/sites-available To activate one of them, run the following … Read more

How do you restart php-fpm?

Note: prepend sudo if not root Using SysV Init scripts directly: /etc/init.d/php-fpm restart # typical /etc/init.d/php5-fpm restart # debian-style /etc/init.d/php7.0-fpm restart # debian-style PHP 7 Using service wrapper script service php-fpm restart # typical service php5-fpm restart # debian-style service php7.0-fpm restart # debian-style PHP 7 Using Upstart (e.g. ubuntu): restart php7.0-fpm # typical (ubuntu … Read more

Nginx config reload without downtime

Run service nginx reload or /etc/init.d/nginx reload It will do a hot reload of the configuration without downtime. If you have pending requests, then there will be lingering nginx processes that will handle those connections before it dies, so it’s an extremely graceful way to reload configs. Sometimes you may want to prepend with sudo

error code: 521