1. nginx配置文件的組成
nginx 由以下幾部分組成
2. nginx 反向代理的使用
proxy_pass指令可以根據規則代理到proxy_pass后的url地址
server_name 用于定義哪些url使用此規則
將gulimaill.com 下所有請求進行代理
負載均衡語法如下 upstream定義于在均衡服務器 proxy_pass使用負載均衡服務器
可以使用此方法代理網關
1
2
3
4
5
6
7
8
9
10
11
12
13
|
http { upstream myapp1 { server srv1.example.com; server srv2.example.com; server srv3.example.com; } server { listen 80 ; location / { proxy_pass http: //myapp1; } } |
1
2
3
4
5
6
7
8
|
upstream gulimall { server 192.168 . 1.7 : 10001 ; } location / { proxy_set_header host $host; # proxy_pass http: //192.168.1.7:10000; proxy_pass http: //gulimall; } |
然后配置gateway
當url為***.gulimaill.com的話 跳轉至商品服務
此處有坑 因為nginx不會攜帶host請求頭 所有還得添加proxy_set_header host $host;配置
到此這篇關于nginx反向代理 的文章就介紹到這了,更多相關nginx反向代理 內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://www.cnblogs.com/lyraHeartstrings/p/15897207.html