Error 502 in nginx + php5-fpm

The issue is socket itself, its problems on high-load cases is well-known. Please consider using TCP\IP connection instead of unix socket, for that you need to make these changes: in php-fpm pool configuration replace listen = /var/run/php5-fpm.sock with listen = 127.0.0.1:7777 in /etc/nginx/php_location replace fastcgi_pass unix:/var/run/php5-fpm.sock; with fastcgi_pass 127.0.0.1:7777;

Nginx Different Domains on Same IP

Your “listen” directives are wrong. See this page: http://nginx.org/en/docs/http/server_names.html. They should be server { listen 80; server_name www.domain1.example; root /var/www/domain1; } server { listen 80; server_name www.domain2.example; root /var/www/domain2; } Note, I have only included the relevant lines. Everything else looked okay but I just deleted it for clarity. To test it you might want … Read more

How to serve all existing static files directly with NGINX, but proxy the rest to a backend server.

Use try_files and named location block (‘@apachesite’). This will remove unnecessary regex match and if block. More efficient. location / { root /path/to/root/of/static/files; try_files $uri $uri/ @apachesite; expires max; access_log off; } location @apachesite { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } Update: The assumption of this config is that … Read more

Use nginx to serve static files from subdirectories of a given directory

It should work, however http://nginx.org/en/docs/http/ngx_http_core_module.html#alias says: When location matches the last part of the directive’s value: it is better to use the root directive instead: which would yield: server { listen 8080; server_name www.mysite.com mysite.com; error_log /home/www-data/logs/nginx_www.error.log; error_page 404 /404.html; location /public/doc/ { autoindex on; root /home/www-data/mysite; } location = /404.html { root /home/www-data/mysite/static/html; } … Read more

nginx docker container: 502 bad gateway response

The Problem Localhost is a bit tricky when it comes to containers. Within a docker container, localhost points to the container itself. This means, with an upstream like this: upstream foo{ server 127.0.0.1:8080; } or upstream foo{ server 0.0.0.0:8080; } you are telling nginx to pass your request to the local host. But in the … Read more

Tuning nginx worker_process to obtain 100k hits per min

Config file: worker_processes 4; # 2 * Number of CPUs events { worker_connections 19000; # It’s the key to high performance – have a lot of connections available } worker_rlimit_nofile 20000; # Each connection needs a filehandle (or 2 if you are proxying) # Total amount of users you can serve = worker_processes * worker_connections … Read more