首頁 >運維 >Nginx >nginx的三種反向代理方式你都知道麼

nginx的三種反向代理方式你都知道麼

王林
王林轉載
2020-11-05 16:36:1018776瀏覽

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刪除