nginx 配置访问正则匹配

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx 配置访问正则匹配相关的知识,希望对你有一定的参考价值。

server{
listen 80;
server_name api.zyy.com;
root /var/www/api_zyy;
index index.php;

location ~ /assets/ {
# access_log logs/static.log common;

#设置静态内容有效期 并且重定向到static
expires 1y;
rewrite ^/static/(.*)$ /static/$1 break;
}

location ~ /static/ {
# access_log logs/static.log common;
expires 1y;
rewrite ^/static/(.*)$ /static/$1 break;
}

#当路径中包含 one 时 进行该路径的访问

location ~ /one/ {
root /var/www/api_zyy/one/web;

rewrite ^(.*)$ /index.php break;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/api_zyy/one/web/index.php;
include fastcgi_params;
}

location ~ /two/ {
root /var/www/api_zyy/two/web;

rewrite ^(.*)$ /index.php break;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/api_zyy/two/web/index.php;
include fastcgi_params;
}

#当什么也匹配不到时  仍然走该配置文件

location ~ / {
root /var/www/api_zyy/two/web;

rewrite ^(.*)$ /index.php break;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/api_zyy/two/web/index.php;
include fastcgi_params;
}

#禁止重写

location ~ /\.ht {
deny all;
}

}

以上是关于nginx 配置访问正则匹配的主要内容,如果未能解决你的问题,请参考以下文章

Nginx 正则匹配配置

nginx 路由配置

Nginx配置转发

Nginx正则匹配详解

nginx 正则匹配配置

Nginx Location 正则表达式