
我希望 nginx 重定向(重寫?)所有對/images
、/css
、或 的/whatever
請求,因為正確地映射到該站點,但當然它總是尋找而不是http://frontend/site/images
http://frontend/site/css
http://frontend/site
backend:port
/whatever
http://frontend/site/whatever
是告訴 nginx 反向代理動態調整 url 的方法嗎?無需建立數百個/location
指令
謝謝
答案1
如果site
是靜態的:
rewrite ^(.*)$ /site/$1 break;
如果site
是主機名稱/網域:
rewrite ^(.*)$ /$host$1 break;
rewrite
也可以在server
區塊中使用:ngx_http_rewrite_module
編輯:
在您發表評論後,答案正好相反:
location /nasweb/ {
rewrite ^/nasweb(/.*)$ $1 break;
proxy_pass http://your-internal-nas;
}
這應該允許您打開https://your-external-domain.com/nasweb/
將您的請求轉發到http://your-internal-nas/
。
編輯:
為了防止錯誤的重定向,請使用以下命令:
proxy_redirect / /nasweb/;