//nginx偽靜態
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
// 根目錄放靜態文件重寫
location /web/{
index index.html;
try_files $uri $uri/ /web/index.html;
}
//重寫 二級目錄指向上級目錄
location ^~ /h5/upload/ {
rewrite /h5/upload/(.*)$ /upload/$1 last;
}
//反向代理
location /api {
rewrite ^.+api/?(.*)$ /$1 break;
proxy_pass http://www.baidu.com; #node api server 即需要代理的IP地址
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /undefined {
rewrite ^.+undefined/?(.*)$ /$1 break;
proxy_pass http://google.com; #node api server 即需要代理的IP地址
}
nginx目錄路徑重定向
1 nginx修改root映射
location /api{
root /web;
}
2 通過nginx rewrite內部跳轉實現訪問重定向
location /api{
rewrite ^/api/(.*)$ /web/api/$1 last;
}
3 nginx設置別名alias映射實現
location /api{
alias /web/api; #這里寫絕對路徑
}
4 通過nginx的permanent 301絕對跳轉實現
location /api{
rewrite ^/api/(.*)$ http://demo.com/web/api/$1;
}
5 通過判斷uri實現頁面跳轉
if ( $request_uri ~* ^(/api)){
rewrite ^/api/(.*)$ /web/api/$1 last;
}
