server {
listen 80;
listen [::]:80;
server_name ~^(?<userName>.*)\.apple\.com\.cn$;
root /export/webapps/apple.com/$userName;
access_log /var/log/nginx/access.log main;
#开启浏览器静态文件缓存
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
expires 3h;
}
# https://<username>.apple.com/api -> /export/webapps/apple.com/api.php #####
location ~* ^/(api|event_api)$ {
root /export/webapps/apple.com;
rewrite ^/(.*)$ /$1.php break;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
fastcgi_buffers 8 256k;
fastcgi_buffer_size 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_intercept_errors on;
}
# https://<username>.apple.com/<uri> -> /export/webapps/apple.com/<username>/<uri>.php
location ~* ^/[0-9a-zA-Z]+$ {
rewrite ^/(.*)$ /$1.php break;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
fastcgi_buffers 8 256k;
fastcgi_buffer_size 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_intercept_errors on;
}
}
location 优先级从上往下依次递减:
location = 仅匹配字符串自身
location ^~ 匹配某个字符串开头的uri
location ~ 正则匹配,区分大小写
location ~* 正则匹配,不区分大小写
location / 表示匹配“域名/之后的uri”,再比如localtion /images,表示匹配“域名/images之后的uri