В качестве значения можно использовать текст, переменные и их комбинации.
Если значение поля заголовка — пустая строка, то поле вообще не будет передаваться проксируемому серверу.
map $uri $a {
default "";
~^/some_uri "Basic YWxhZGRpbjpvcGVuc2VzYW1l";
}
proxy_set_header Authorization $a;
server {
server_name neel_rl.neel;
root /var/www/neel/appRlLara/legacy;
location / {
try_files $uri /index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass rl.php54:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
location /appRlLara {
root /var/www/neel/appRlLara/public;
rewrite ^/appRlLara/(.*) /$1 break;
try_files $uri /appRlLara/index.php$is_args$args;
location ~ \.php$ {
rewrite ^/appRlLara/(.*) /$1 break;
fastcgi_pass rl.php54:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
test(.*)
совпадает с test2.test/(.*)
rewrite ^/catalog/test/(.*) /catalog/test2/$1 permanent;
geo $lan {
default no;
123.224.55.2 yes;
}
map "$lan,$geoip2_data_country_code" $allowed_country {
default no;
~^yes yes;
~,UA yes;
~,BG yes;
~,RO yes;
}
rewrite ^/api/ /index.php?id=131 last;
AddType application/x-httpd-php .html .htm
if ($request_uri ~ "/index\.htm") {
return 301 /;
}
if ($request_uri ~ "^([^.?]+)\.htm") {
return 301 $1;
}
location / {
try_files $uri $uri/ $uri.htm$is_args$args;
}
location ~ \.htm {
try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location /link/ {
proxy_pass https://site1.ru/;
/link/
будет заменён на /
в итоге получится https://site1.ru/pDK9VJacsrb9bway?no=2location /link/ {
proxy_pass https://site1.ru;
proxy_set_header Host $host;
server {
listen 443 ssl http2;
server_name alias.domen.ru;
ssl_certificate ... ;
ssl_certificate_key ... ;
return 301 https://domen.ru/link/landing;
}
if
чтобы избежать зацикливания.if ($host = alias.domen.ru) {
return 301 https://domen.ru/link/landing;
}
location /sandbox/hello/ {
try_files $uri $uri/ /sandbox/hello/index.php$is_args$args;
}
server {
listen 80;
listen [::]:80;
root /var/www/example_com;
index index.html index.php;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /sandbox/hello/ {
try_files $uri $uri/ /sandbox/hello/index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Регулярные выражения задаются либо с модификатором “~*” (для поиска совпадения без учёта регистра символов), либо с модификатором “~” (с учётом регистра).
(?<name>...)
set $test $1;
location ~ ^/(?<test>test-a-[0-9]|test-b-[0-9]) {
proxy_pass http://$test;
location = /admin/index.php {
if ($arg_route ~ "/mod2") {
rewrite ^ mod2 last;
}
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_read_timeout 60;
}
location = mod2 {
rewrite ^ /admin/index.php break;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_read_timeout 1000;
}
Мне необходимо написать так, что если метод не POST (GET, HEAD), то выдавать не 0.
map $request_method $cache_hit {
"~*post" 0;
default 1;
}
map $request_method $cache_hit {
POST 0;
default 1;
}
set $cache_hit 1;
# POST requests and urls with a query string should always go to PHP.
if ($request_method = POST) {
set $cache_hit 0;
}
if ($query_string != "") {
set $cache_hit 0;
}
# Don't cache uris containing the following segments.
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_hit 0;
}
# Don't use the cache for logged-in users or recent commenters.
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_hit 0;
}
map $query_string $check_query_string {
"" 0;
default 1;
}
map $request_uri $check_request_uri {
"~*(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)" 1;
default 0;
}
map $http_cookie $check_cookie {
"~*comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in" 1;
default 0;
}
map "$request_method:$check_query_string:$check_request_uri:$check_cookie" $cache_hit {
"~^POST" 0;
"~1" 0;
default 1;
}
map "$geoip_country_code,$http_user_agent" $deny {
default 0;
~^US.*Googlebot 0;
~^US 1;
~^CN 1;
}
server {
if ($deny) {
return 403;
}
ssl on;
Эта директива устарела в версии 1.15.0. Вместо неё следует использовать параметр ssl директивы listen.
server {
listen 443 ssl http2;
RewriteRule ^page/([0-9]+)/$ index.php?page=$1 [L,QSA]
RewriteRule ^cat/([0-9]+)/(.*)/([0-9]+)/$ cat.php?id=$1&name=$2&page=$3 [L,QSA]
RewriteRule ^cat/([0-9]+)/(.*)/$ cat.php?id=$1&name=$2 [L,QSA]
RewriteRule ^collections/$ collections.php [L,QSA]
RewriteRule ^collections/([0-9]+)/$ collections.php?page=$1 [L,QSA]
RewriteRule ^search/(.*)/([0-9]+)/$ search.php?q=$1&page=$2 [L,QSA]
RewriteRule ^search/(.*)/$ search.php?q=$1 [L,QSA]
rewrite ^/page/([0-9]+)/$ /index.php?page=$1 last;
rewrite ^/cat/([0-9]+)/(.*)/([0-9]+)/$ /cat.php?id=$1&name=$2&page=$3 last;
rewrite ^/cat/([0-9]+)/(.*)/$ /cat.php?id=$1&name=$2 last;
rewrite ^/collections/$ /collections.php last;
rewrite ^/collections/([0-9]+)/$ /collections.php?page=$1 last;
rewrite ^/search/(.*)/([0-9]+)/$ /search.php?q=$1&page=$2 last;
rewrite ^/search/(.*)/$ /search.php?q=$1 last;
if ($http_referer ~* "^https?://(site1\.ru|site2\.com|site3\.org)") {
return 403;
}
valid_referers ~^(?!site1\.ru|site2\.com|site3\.org);
if ($invalid_referer) {
return 403;
}