server {
error_page 404 = $document_root/404.html;
set $cats $cookie_q;
if ($cats = 0) {
set $cats $args_q;
}
if ($cats = 0) {
return 404;
}
listen 80;
server_name site.ru www.site.ru;
root /path/to/site/public_html;
rewrite ^([^.\?]*[^/])$ $1/ permanent;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location = /wp-login.php {
deny all;
return 404;
}
location ~* \.(git|htaccess|htpasswd)$ {
deny all;
return 404;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\.ht {
deny all;
return 404;
}
location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|xlsx|ppt|rar|rpm|swf|zip|bin|deb|cur|ttf|woff|woff2|svg|xml|json|eot)$ {
expires 180m;
}
location ~* \.(css|js)$ {
expires 180m;
}
location / {
fastcgi_intercept_errors on;
try_files $uri $uri/index.php /index.php 404;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
map "$arg_q:$cookie_q" $my_upstream {
default 404;
"~^:(?<cookie>.+)$" $cookie;
"~^(?<get>.+):$" $get;
}
server {
if ($my_upstream = 404) {
return 404;
}
...
proxy_pass http://$my_upstream;