通过把Nginx设置为正向代理,我们就可以在局域网中用运行着Nginx的主机作为正向代理服务器了。那什么是正向代理和反向代理呢?正向代理和反向代理-百度百科
正向代理:如果把局域网外的Internet想象成一个巨大的资源库,则局域网中的客户端要访问Internet,则需要通过代理服务器来访问,这种代理服务就称为正向代理。
反向代理:如果局域网向Internet提供资源服务,让Internet上的其他客户端来访问局域网内的资源,使它们必须通过一个代理服务器来进行访问,这种服务就称为反向代理。正向代理和反向代理逻辑正好相反。
Nginx正向代理涉及到的指令较少,下面直接贴上其配置文件内容。
[root@ali conf]# cat nginx.conf #user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; #keepalive_timeout 0; keepalive_timeout 65; upstream nexus.cafintech.service { server 172.17.1.82:8081; } server { listen 80; server_name nexus.cafintech.service; location / { proxy_pass http://nexus.cafintech.service; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream gitlab.cafintech.service { server 172.17.1.80:80; } server { listen 80; server_name gitlab.cafintech.service; location / { proxy_pass http://gitlab.cafintech.service; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream jenkins.c.com { server 10.2.4.92; } server { listen 80; server_name jenkins.c.com; location / { proxy_pass http://jenkins.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream es.c.com { server 10.1.5.29:9200; } server { listen 80; server_name es.c.com; location / { proxy_pass http://es.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream grunt.c.com { server 10.1.56.2:9100; } server { listen 80; server_name grunt.c.com; location / { proxy_pass http://grunt.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream sesame.c.test { server 172.17.1.103; } server { listen 81; server_name sesame.c.test; location / { proxy_pass http://sesame.c.test; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream cm.c.com { server 10.19.5.2:7180; } server { listen 80; server_name cm.c.com; location / { proxy_pass http://cm.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream hue.c.com { server 10.1.57.2:8888; } server { listen 80; server_name hue.c.com; location / { proxy_pass http://hue.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream azkaban.c.com { server 10.3.57.2:8081; } server { listen 80; server_name azkaban.c.com; location / { proxy_pass http://azkaban.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream metadata.c.com { server 10.19.49.61; } server { listen 80; server_name metadata.c.com; location / { proxy_pass http://metadata.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream elk.c.com { server 10.253.41.98; } server { listen 80; server_name elk.c.com; location / { proxy_pass http://elk.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream alert.c.com { server 10.139.8.118; server 10.139.9.83; } server { listen 80; server_name alert.c.com; location / { proxy_pass http://alert.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream eureka.c.com { server 10.19.3.119; } server { listen 80; server_name eureka.c.com; location / { proxy_pass http://eureka.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } upstream admin.c.com { server 10.19.57.12; } server { listen 80; server_name admin.c.com; location / { proxy_pass http://admin.c.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { index html; } } } [root@ali conf]#
想用域名访问,配置一下本地hosts文件即可
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论