Table of Contents

Engine-X web server

Troubleshooting

413: Request Entity Too Large

If the size in a request exceeds the configured value, the error 413 is returned. Setting size to 0 disables checking of client request body size.

client_max_body_size 8M;

Redirects

old to new domain

/etc/nginx/conf.d/userdirs.conf
server {
    listen 80;
    listen 443 ssl;
    server_name www.old-name.com old-name.com;
    return 301 $scheme://www.new-name.com$request_uri;
}

Rewrites

https://www.nginx.com/blog/creating-nginx-rewrite-rules/

userdirs

/etc/nginx/conf.d/userdirs.conf
server {
  listen 80;
  server_name example.com;
  location ~ ^/~(.+?)(/.*)?$ {
    alias /home/$1/html$2;
    index index.html;
    autoindex on;
  }
}

only if file doesn't exist

/etc/nginx/conf.d/userdirs.conf
location / {
    if (-f $request_filename) {
        break;
    }
    rewrite ^ http://example.com$request_uri? permanent
}

software specific

php-fpm

PHP config

/etc/php/php-fpm.conf
include=/etc/php/fpm.d/*.conf
/etc/php/fpm.d/example-com.conf
[example.com]
listen = /run/php-fpm/example.com.sock
 
# owner of the socket file
listen.owner = http
 
# owner of the files in the web root
user = example
group = users
 
# for low load and many pools
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s

nginx config

main block

/etc/nginx/nginx.conf
worker_processes  1;
error_log  /var/log/nginx/error.log;
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    log_format  main  '$remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
 
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
 
    server {
        listen       80;
        server_name  localhost;
 
        location / {
            root   /srv/http/;
            index  index.html index.htm index.php;
            autoindex on;
            location ~ \.php {
                    fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
                    include /etc/nginx/fastcgi_params
            }
        }
    }
    include		/etc/nginx/sites/*.conf;
}

site specific

/etc/nginx/sites/com.example.subdomain.conf
server {
	listen 80;
	server_name example.com;
	root /srv/http/example.com/;
 
	location ~ ^(.+?\.php)(/.*)?$ {
		include /etc/nginx/fastcgi_params;
		fastcgi_pass unix:/run/php-fpm/example.com.sock;
	}
}

Reverse Proxy

Apache on port 8090

/etc/nginx/conf.d/userdirs.conf
       location / {
                proxy_pass http://127.0.0.1:8090;
                include /etc/nginx/proxy_params;
       }
       location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
       }

IPv6

For nginx to listen properly on IPv6, you need two listen directives:

server {
        listen 80;
        listen [::]:80;}

Headers

FLoC

https://amifloced.org/

server {add_header Permissions-Policy "interest-cohort=()";}

tools


[1] written by DigitalOcean, code: github