首页 > 运维 > nginx > nginx的三种反向代理方式你都知道么

nginx的三种反向代理方式你都知道么

王林
发布: 2020-11-05 16:36:10
转载
18755 人浏览过

nginx的三种反向代理方式你都知道么

nginx反向代理的三种模式分别是:

1、基于IP代理

2、基于域名代理

3、基于端口代理

(相关教程推荐:nginx教程

nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}

http {
	charset utf-8;
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

	# log_format  main  'remote_addr=$remote_addr:$remote_port, http_x_forwarded_for=$http_x_forwarded_for, proxy_add_x_forwarded_for=$proxy_add_x_forwarded_for ';
    access_log  logs/access_format.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on
	
	# 原始server
	server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
    }
	# 引入自定义的server配置
	include my-proxy-server.conf;
}
登录后复制

my-proxy-server.conf

########################################################################
# 基于端口代理
########################################################################
server {
	listen       81;
	server_name  localhost;
	location / {
		proxy_pass http://192.168.0.153:9091;
		proxy_redirect default;
	}
	location = /50x.html {
		root   html;
	}
}
server {
	listen       82;
	server_name  localhost;
	location / {
		proxy_pass http://git.itplh.com;
		proxy_redirect default;
	}
	location = /50x.html {
		root   html;
	}
}

########################################################################
# 基于域名代理 + gitlocal负载均衡
########################################################################
upstream gitlocal{
  server 192.168.0.153:9091;
  server 192.168.0.154:9091;
  server 192.168.0.155:9091;
}
upstream gitbj{
  server git.itplh.con;
}
server {
    listen       80;
    server_name  gitlocal.com;
    location / {
        proxy_pass http://gitlocal;
        proxy_redirect default;
    }
    location = /50x.html {
        root   html;
    }
}
server {
    listen       80;
    server_name  gitbj.com;
    location / {
        proxy_pass http://gitbj;
        proxy_redirect default;
    }
    location = /50x.html {
        root   html;
    }
}
登录后复制

以上是nginx的三种反向代理方式你都知道么的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:csdn.net
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板