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;
}
rewrite ^/test$ /test.php;
location / {
try_files $uri @php;
}
location @php {
try_files $uri.php =404;
fastcgi_pass ... ;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
php.mysite.ru/phpmyadmin
было php.mysite.ru/
нужно исправить root путь.server {
listen 80;
listen [::]:80;
root /var/www/html/phpmyadmin;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name php.mysite.ru
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
https://site.ru
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name site.ru;
ssl_certificate ... ;
ssl_certificate_key ... ;
}
Если у совпавшего префиксного location’а максимальной длины указан модификатор “^~”, то регулярные выражения не проверяются.
location /site2/
добавить ^~
location /site1 {
добавить location ~* \.php$
location /site1 {
root /var/www/site1;
location ~* \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; # подключаем сокет php-fpm
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location ^~ /site2/ {
proxy_pass https://site2/;
}