nginx作為正向代理,反向代理的一些應用
阿新 • • 發佈:2019-01-05
3.2 span proxy 利用 gin return 服務 main oot
正向代理代理的對象是客戶端
反向代理代理的對象是服務端
舉例說下nginx作為正向代理作訪問控制
server{ listen 80; server_name localhost jeson.gaosf.com; access_log /var/log/nginx/log/host.access.log main; location /{ if($http_x_forwarded_for !~* "^116\.62\.103\.228"){ return 403; } root /opt/app/code; index index.html index.htm; } }
利用http_x_forwarded_for 來識別是不是116.62.103.228這個ip,不是的話就返回403
反向代理的例子:
在/etc/nginx/conf.d下的realserver.conf裏面
server{ listen 8080; server_name localhost jeson.gaosf.com; access_log /var/log/nginx/log/serve.access.log main; location /{ root /opt/app/code2; index index.html index.htm; } }
在/opt/app/code2下有個test_proxy.html文件
在/etc/nginx/conf.d下的fx_proxy.conf裏面
server{ listen 80; server_name localhost jeson.gaosf.com; access_log /var/log/nginx/log/host.access.log main; location /{ root /usr/share/nginx/html; index index.html index.htm; }//當匹配test_proxy.html,會代理8080端口 location ~/test_proxy.html${ proxy_pass http://127.0.0.1:8080; } }
然後查看下
netstat -luntp|grep nginx
查看下狀態
nginx作為正向代理,反向代理的一些應用