Skip to main content

Nginx Tips

Multi Level SubDirectory Setup which is not a multisite.

If a multilevel subdirectory install is required , make sure /dir/mappedsite is a symbolic link . For single level the rewrite is not required. Also make sure that safe path is updated accordingly.

# If subdirectory is there match files inside the subdirectory 
location /de/fernstudium {
        index index.php index.html index.htm;
        try_files $uri $uri/ /de/fernstudium/index.php?q=$uri&$args;
    }

# So that /de is not matched as a domain 
rewrite ^/de(.?!(fernstudium)*)$ $1 last;

Subdirectory Setup with reverse proxy

This is used when the subdirectory is on a different server. wordpress homeurl and siteurl also to be updated.

location ~/news(.*)$ {
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host news.erudera.com;
            proxy_pass http://172.104.155.54:80$1$is_args$args;
 }
 

Rate limiting

Limit request to php to slow down crawlers and other CPU eating bots . Limits to 1 req per second with a burst of 3 -

In the main file nginx.conf -

limit_req_zone $binary_remote_addr zone=phplimit:10m rate=1r/s;
limit_req_zone $http_cf_connecting_ip zone=cfphplimit:10m rate=1r/s;

limit_conn_status 429;
limit_req_status 429;

This can be put in files with php location block -

limit_req zone=phplimit burst=3 ;
limit_req zone=cfphplimit burst=3 ;
limit_req_dry_run off;

Rate Limiting in Nginx:https://www.nginx.com/blog/rate-limiting-nginx/

Ratelimiting info is availbile in logs