伪静态:
location /api/ {
if (!-e $request_filename) {
rewrite ^(.*)$ /api/index.php$1 last;
}
}
location /blog/ {
if (!-e $request_filename) {
rewrite ^(.*)$ /blog/index.php$1 last;
}
}
flag标记有
- last 相当于Apache里的[L]标记,表示完成rewrite
- break 终止匹配, 不再匹配后面的规则
- redirect 返回302临时重定向 地址栏会显示跳转后的地址
- permanent 返回301永久重定向 地址栏会显示跳转后的地址
反向代理:
location /cgi
{
proxy_pass http://127.0.0.1:90;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
#add_header Cache-Control no-cache;
#expires 12h;
}