本文摘自PHP中文网,作者V,侵删。

nginx反向代理的三种模式分别是:
1、基于IP代理
2、基于域名代理
3、基于端口代理
(相关教程推荐:nginx教程)
nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | ########################################################################
# 基于端口代理
########################################################################
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的三种反向代理方式你都知道么的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
使用 nginx 反向代理多个 docker 容器
nginx根据ip跳转不同页面
nginx与php的两种通信方式是什么
nginx上出现403应该怎么解决
详解nginx高并发配置参数
nginx调优主要调哪些
细说nginx的内置变量
nginx属于什么意思
nginx怎么实现负载均衡的
nginx怎么限流
更多相关阅读请进入《nginx》频道 >>
转载请注明出处:木庄网络博客 » nginx的三种反向代理方式你都知道么