Answer the question
In order to leave comments, you need to log in
How to configure nginx to handle cookies?
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;
}
Answer the question
In order to leave comments, you need to log in
It is done standardly via map (written in the http section!):
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;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question