Nginx 多重条件判断
server{
listen 80;
server_name xxx.com;
index index.html index.htm index.php admin.php;
root /home/wwwroot/default/wounion/dragonfly/public;
#error_page 404 /404.html;
#include enable-php.conf;
include enable-php-pathinfo.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location / {
if ($request_filename ~* "wounion") {
rewrite ^/wounion/(.*)$ /api.php?s=$1 last;
}
if (!-e $request_filename) {
rewrite ^(.*)$ /admin.php?s=$1 last;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
Nginx 常用的匹配
~ 为区分大小写匹配
~* 为不区分大小写匹配
!~和!~*分别为区分大小写不匹配及不区分大小写不匹配
-f和!-f用来判断是否存在文件
-d和!-d用来判断是否存在目录
-e和!-e用来判断是否存在文件或目录
-x和!-x用来判断文件是否可执行