網站首頁 編程語言 正文
1.ngx_stream_proxy_module
模塊的proxy_pass
指令
只能在server段使用使用, 只需要提供域名或ip地址和端口。
可以理解為端口轉發,可以是tcp端口,也可以是udp端口。
server { listen 127.0.0.1:12345; proxy_pass 127.0.0.1:8080; } server { listen 12345; proxy_connect_timeout 1s; proxy_timeout 1m; proxy_pass example.com:12345; } server { listen 53 udp; proxy_responses 1; proxy_timeout 20s; proxy_pass dns.example.com:53; } server { listen [::1]:12345; proxy_pass unix:/tmp/stream.socket;
2.ngx_http_proxy_module
模塊的proxy_pass
指令
- 需要在location段,location中的if段,limit_except段中使用,
- 處理需要提供域名或ip地址和端口外,還需要提供協議,如"http"或"https",
- 還有一個可選的uri可以配置。
3.proxy_pass后,后端服務器的url(request_uri)情況分析
server { listen 80; server_name www.test.com; # 情形A # 訪問 http://www.test.com/testa/aaaa # 后端的request_uri為: /testa/aaaa location ^~ /testa/ { proxy_pass http://127.0.0.1:8801; } # 情形B # 訪問 http://www.test.com/testb/bbbb # 后端的request_uri為: /bbbb location ^~ /testb/ { proxy_pass http://127.0.0.1:8801/; } # 情形C # 下面這段location是正確的 location ~ /testc { proxy_pass http://127.0.0.1:8801; } # 情形D # 下面這段location是錯誤的 # # nginx -t 時,會報如下錯誤: # # nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular # expression, or inside named location, or inside "if" statement, or inside # "limit_except" block in /opt/app/nginx/conf/vhost/test.conf:17 # # 當location為正則表達式時,proxy_pass 不能包含URI部分。本例中包含了"/" location ~ /testd { proxy_pass http://127.0.0.1:8801/; # 記住,location為正則表達式時,不能這樣寫!!! } # 情形E # 訪問 http://www.test.com/ccc/bbbb # 后端的request_uri為: /aaa/ccc/bbbb location /ccc/ { proxy_pass http://127.0.0.1:8801/aaa$request_uri; } # 情形F # 訪問 http://www.test.com/namea/ddd # 后端的request_uri為: /yongfu?namea=ddd location /namea/ { rewrite /namea/([^/]+) /yongfu?namea=$1 break; proxy_pass http://127.0.0.1:8801; } # 情形G # 訪問 http://www.test.com/nameb/eee # 后端的request_uri為: /yongfu?nameb=eee location /nameb/ { rewrite /nameb/([^/]+) /yongfu?nameb=$1 break; proxy_pass http://127.0.0.1:8801/; } access_log /data/logs/www/www.test.com.log; } server { listen 8801; server_name www.test.com; root /data/www/test; index index.php index.html; rewrite ^(.*)$ /test.php?u=$1 last; location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } access_log /data/logs/www/www.test.com.8801.log; }
原文鏈接:https://www.cnblogs.com/qumogu/p/15618533.html
相關推薦
- 2022-11-21 C#基礎知識之字符串和正則表達式_C#教程
- 2022-05-11 React中的Refs屬性你來了解嗎_React
- 2022-10-22 C#中的屬性解析(get、set、value)_C#教程
- 2022-10-12 docker配置阿里云鏡像倉庫的實現_docker
- 2022-03-18 c語言的指針數組詳解(c語言指針與數組)
- 2022-07-30 centos 創建python虛擬環境遇到的問題及解決方法
- 2022-09-14 python?服務器批處理得到PSSM矩陣的問題_python
- 2023-03-15 k8s編排之StatefulSet知識點詳解一_云其它
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支