nginx中的proxy_redirect的使用案例詳解
一 proxy_redirect的作用
proxy_redirect 該指令用來修改被代理服務器返回的響應頭中的Location頭域和“refresh”頭域。
二 語法結(jié)構(gòu)
proxy_redirect 舊地址 新地址; proxy_redirect default; #默認配置 proxy_redirect off; #關閉重定向
三 案例
如果需要修改從被代理服務器傳來的應答頭中的"Location"和"Refresh"字段,可以用這個指令設置。
1.假設被代理服務器返回Location字段為: http://localhost:8000/two/some/uri/
這個指令:proxy_redirect http:
//localhost
:8000
/two/
http:
//frontend/one/
;
將Location字段重寫為http://frontend/one/some/uri/。
2.在代替的字段中可以不寫服務器名:
proxy_redirect http://localhost:8000/two/ /;
這樣就使用服務器的基本名稱和端口,即使它來自非80端口。
3.參數(shù)off將在這個字段中禁止所有的proxy_redirect指令:
proxy_redirect off; proxy_redirect default; proxy_redirect http://localhost:8000/ /; proxy_redirect ; /;1.
4.利用proxy_redirect這個指令可以為被代理服務器發(fā)出的相對重定向增加主機名:
擴展:nginx proxy_redirect https配置后端http302跳轉(zhuǎn)處理
# HTTPS server # server { listen 443 ssl; server_name localhost; charset utf8; ssl_certificate full_chain.pem; ssl_certificate_key private.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; 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 X-Forwarded-Proto $scheme; proxy_connect_timeout 10; proxy_send_timeout 90; proxy_read_timeout 90; proxy_redirect http://$host/ https://$host:$server_port/; location /mgr/ { proxy_pass http://localhost:8080/mgr/; } }
到此這篇關于nginx中的proxy_redirect的使用的文章就介紹到這了,更多相關nginx proxy_redirect的使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Nginx記錄分析響應慢的請求及替換網(wǎng)站響應內(nèi)容的配置
這篇文章主要介紹了Nginx記錄分析響應慢的請求及替換網(wǎng)站響應內(nèi)容的配置,分別用到了ngx_http_log_request_speed模塊和ngx_http_sub_module模塊,需要的朋友可以參考下2016-01-01Keepalived+Nginx+Tomcat 實現(xiàn)高可用Web集群的示例代碼
這篇文章主要介紹了Keepalived+Nginx+Tomcat 實現(xiàn)高可用Web集群的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09Nginx 解決WebApi跨域二次請求以及Vue單頁面的問題
下面小編就為大家分享一篇Nginx 解決WebApi跨域二次請求以及Vue單頁面的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01Nginx 服務器開啟status頁面檢測服務狀態(tài)的方法
這篇文章主要介紹了Nginx 服務器開啟status頁面檢測服務狀態(tài)的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01Nginx使用ngx_http_upstream_module實現(xiàn)負載均衡功能示例
本文主要介紹了Nginx使用ngx_http_upstream_module實現(xiàn)負載均衡功能示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-08-08