Nginx正向代理配置

IT
IT
IT
335
文章
1
评论
2020年5月21日14:06:23 评论 1,222 3200字阅读10分40秒

通过把Nginx设置为正向代理,我们就可以在局域网中用运行着Nginx的主机作为正向代理服务器了。那什么是正向代理和反向代理呢?正向代理和反向代理-百度百科

正向代理:如果把局域网外的Internet想象成一个巨大的资源库,则局域网中的客户端要访问Internet,则需要通过代理服务器来访问,这种代理服务就称为正向代理。

Nginx正向代理配置

反向代理:如果局域网向Internet提供资源服务,让Internet上的其他客户端来访问局域网内的资源,使它们必须通过一个代理服务器来进行访问,这种服务就称为反向代理。正向代理和反向代理逻辑正好相反。

Nginx正向代理配置

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文件即可

2017082815552943

 

继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
IT
  • 本文由 发表于 2020年5月21日14:06:23
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
部署Nginx负载均衡器【待续】 nginx

部署Nginx负载均衡器【待续】

kube-apiserver高可用架构图 涉及软件 Keepalived是一个主流高可用软件,基于VIP绑定实现服务器双机热备,在上述拓扑中, Keepalived主要根据Nginx运行状态判断是否需...
nginx反向代理获取用户真实ip nginx

nginx反向代理获取用户真实ip

提要 nginx做反向代理时,默认的配置后端获取到的ip都是来自于nginx,那么如何转发用户的真实IP到后端程序呢? 当前端使用nginx代理,后端使用php-fpm时,如果还是使用$_SERVER...