nginx多层反代配置变量proxy_set_header
Nginx多层反代配置变量proxy_set_header过程记录
第一层代理:
(1)路径:
$ vim /data/soft/nginx/conf/vhost/xixi.conf
(2)内容:(注:此处变量名需中划线。)
server {
listen 80;
server_name api.xxx.com api.yyyy.com api.cun.com;
access_log /log/nginx/xiaojicdn.api.log main;
root /data/www/pay/;
location /member {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header real-remote $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://member.srv;
}
location /discount {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header real-remote $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://discount.srv;
}
location /pay {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header real-remote $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://pay.srv;
}
location /agent {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header real-remote $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://agent.srv;
}
location =/pay.html {
expires 10s;
}
location =/ {
index index.html payment.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /500.html;
location = /500.html {
default_type application/json;
add_header Content-Type 'application/json; charset=utf-8';
return 200 '{"status":2, "msg":"Server Error!"}';
}
location = /404.html {
default_type application/json;
add_header Content-Type 'application/json; charset=utf-8';
return 200 '{"status":2, "msg":"Request Uri Not Found!"}';
}
}
第二层代理:
(1) 路径:
$ vim /data/soft/nginx/conf/vhost/xixi.conf
(2) 内容:(注:此处变量获取需加http头,并且中划线要变为下划线。)
server {
listen 5675;
server_name m.ttcn.com m.xxy.com api.xxx.com api.xxg.com api.ren.com;
access_log /log/nginx/xiaoji.game.api.log main;
location /member {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_real_remote;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://member.srv;
}
location /discount {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_real_remote;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://discount.srv;
}
location /pay {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_real_remote;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://pay.srv;
}
location /agent {
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_real_remote;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://agent.srv;
}
error_page 404 /404.html;
error_page 500 502 503 504 /500.html;
location = /500.html {
default_type application/json;
add_header Content-Type 'application/json; charset=utf-8';
return 200 '{"status":2, "msg":"Server Error!"}';
}
location = /404.html {
default_type application/json;
add_header Content-Type 'application/json; charset=utf-8';
return 200 '{"status":2, "msg":"Request Uri Not Found!"}';
}
}
(3) 路径:
$ vim /data/soft/nginx/conf/nginx.conf
(4) 内容:
user root;
worker_processes 8;
worker_rlimit_nofile 65535;
worker_cpu_affinity auto;
daemon on;
error_log /log/nginx/error.log error;
pid /log/nginx/nginx.pid;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
include upstream.conf;
default_type text/plain;
### core
charset utf-8;
server_names_hash_bucket_size 128;
server_names_hash_max_size 512;
connection_pool_size 512;
server_tokens off;
chunked_transfer_encoding on;
### tcp/socket/DDOS
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_body_timeout 15s;
client_header_timeout 15s;
send_timeout 15s;
resolver_timeout 5s;
keepalive_requests 500;
keepalive_timeout 45s;
### open file
open_file_cache max=60000 inactive=60s;
open_file_cache_valid 60s;
open_file_cache_min_uses 1;
open_file_cache_errors on;
### client buffer
client_header_buffer_size 4k;
large_client_header_buffers 8 16k;
ignore_invalid_headers on;
client_body_buffer_size 16k;
client_max_body_size 10m;
client_body_temp_path client_body_temp;
### response config
output_buffers 4 32k;
### gzip
gzip on;
gzip_http_version 1.1;
gzip_disable "msie6";
gzip_comp_level 5;
gzip_min_length 100;
gzip_proxied any;
gzip_buffers 16 4k;
gzip_vary on;
# gzip types
gzip_types text/plain;
gzip_types text/css;
gzip_types application/javascript;
gzip_types application/json;
gzip_types application/vnd.ms-fontobject;
gzip_types application/x-font-ttf;
gzip_types font/opentype;
gzip_types image/svg+xml;
gzip_types image/x-icon;
### proxy cache
proxy_connect_timeout 5;
proxy_read_timeout 30;
proxy_send_timeout 10;
proxy_http_version 1.1;
proxy_request_buffering on;
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 32 4k;
proxy_busy_buffers_size 16k;
proxy_max_temp_file_size 1024m;
proxy_temp_file_write_size 32k;
proxy_ignore_client_abort off;
proxy_intercept_errors on;
proxy_limit_rate 0;
proxy_pass_request_body on;
proxy_pass_request_headers on;
proxy_next_upstream error timeout http_502;
#proxy_cache proxy_cache1;
proxy_cache off;
proxy_cache_key $scheme$proxy_host$request_uri;
proxy_cache_lock_age 5s;
proxy_cache_lock_timeout 5s;
proxy_cache_methods GET HEAD;
proxy_cache_min_uses 1;
proxy_cache_valid 200 302 1m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;
proxy_cache_path /log/nginx/proxy_cache levels=1:2 keys_zone=proxy_cache1:4096m inactive=60s max_size=4g;
proxy_temp_path /log/nginx/proxy_cache_tmp;
### connection limit
#limit_conn_zone $binary_remote_addr zone=perip:100m;
#limit_conn_status 503;
#limit_conn_log_level error;
#limit_conn perip 6;
### request limit
#limit_req_zone $binary_remote_addr zone=pereq:200m rate=2r/s;
#limit_req zone=pereq burst=5 nodelay;
#limit_req_log_level error;
#limit_req_status 503;
### limit response
#limit_rate 4k;
#limit_rate_after 500k;
### log format
log_format main escape=json
'{"nx_localtime@timestamp":"$time_local",'
'"nx_host":"$server_addr",'
'"nx_client_ip":"$http_real_remote",'
'"nx_body_size":$body_bytes_sent,'
'"nx_request_time":$request_time,'
'"nx_scheme":"$scheme",'
'"nx_http_host":"$host",'
'"nx_request_method":"$request_method",'
'"nx_uri":"$uri",'
'"nx_status":$status,'
'"nx_referer":"$http_referer",'
'"nx_agent":"$http_user_agent",'
'"nx_upstream_host":"$upstream_addr",'
'"nx_upstream_time":$upstream_response_time,'
'"nx_upstream_response_length":$upstream_response_length,'
'"nx_upstream_status":$upstream_status,'
'"nx_upstream_connect_time":$upstream_connect_time}';
open_log_file_cache max=1000 inactive=60s min_uses=1 valid=60s;
access_log off;
#access_log /log/nginx/access.log main buffer=1M gzip=4 flush=5m;
log_not_found on;
### forbit ip access
server {
listen 80 default;
server_name _;
return 404;
}
include vhost/*.conf;
}
(5) 查看日志内容:

则client_ip为真是的远程客户端访问ip,而不是第一层代理或者第一层代理和远程客户端两个IP了。
nginx多层反代配置变量proxy_set_header的更多相关文章
- nginx负载均衡(5种方式)、rewrite重写规则及多server反代配置梳理
Nginx除了可以用作web服务器外,他还可以用来做高性能的反向代理服务器,它能提供稳定高效的负载均衡解决方案.nginx可以用轮询.IP哈希.URL哈希等方式调度后端服务器,同时也能提供健康检查功能 ...
- (转)nginx负载均衡(5种方式)、rewrite重写规则及多server反代配置梳理
Nginx除了可以用作web服务器外,他还可以用来做高性能的反向代理服务器,它能提供稳定高效的负载均衡解决方案.nginx可以用轮询.IP哈希.URL哈希等方式调度后端服务器,同时也能提供健康检查功能 ...
- Nginx/Httpd反代tomcat配置
在上一篇博客中,我们了解了tomcat的server.xml中各组件的用法和作用:其中对于tomcat连接器来说,它分三类,一类是http连接器,一类是https连接器,一类是ajp连接器:通常tom ...
- tomcat 反代配置
tomcat反代可以基于nginx , http进行反代 反代服务器: 有两个网口 反代服务器一般有两块网卡一块处于外网,一块处于内网用于与后端服务器通信 tomcat 节点处于内网地址 1 tom ...
- 使用nginx做反代时遇到413 Request Entity Too Large的解决方法
在使用nginx做反向代理的时候,被反代的系统在上传文件的时候遇到413 错误 :Request Entity Too Large 原因是nginx限制了上传文件的大小,在nginx中可以配置最大允许 ...
- nginx反代及后端web配置
一.反代配置,proxy_pass指向的upstream需要在反代的nginx.conf中配置 server {access_log /home/nginx/front_access.log;erro ...
- Nginx反代MogileFS集群
上一篇博文我们主要聊了下分布式文件系统MogileFS的组件以及部署使用,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13677279.html:今天我们主要 ...
- Nginx反代Mogilefs分布式储存示例
一.分布式存储系统简介 随着信息技术不断的发展,给我们带来便利的同时,不断增加的数据量级.信息之间的连接关联越来越复杂.数据访问的并发量日益增加对I/O的要求越来越高.数据类型越来越复杂等难题也成为信 ...
- Nginx反代,后端一个IP绑定多个SSL证书,导致连接失败之解决方法:HTTPS和SNI扩展
默认:SSL协议进行握手协商进行连接的时候,默认是不会发送主机名的,也就是是以IP的形式来进行https连接握手协商的,这就导致一个问题,当一台服务器上有多个虚拟主机使用同一个IP的时候, Nginx ...
随机推荐
- 创建maven web项目时,没有web.xml文件
1.问题:创建maven项目时,选择的是创建web-app项目,但是结果配置之后,却没有web.xml文件. 2.解决办法: ------------------------------------- ...
- uniapp 之navigateTo:fail page 跳转路径不对
开发uniapp,点击列表跳转详情报错 [system] navigateTo:fail page `/pages/tabBar/index/detail/detail?title=uni-app行业 ...
- SpringBoot:初识SpringBoot
西部开源-秦疆老师:基于SpringBoot 2.1.6 的博客教程 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处!防君子不防小人,共勉! 1.SpringBo ...
- 转:SqlBulkCopy类进行大数据(一万条以上)插入测试
转自:https://www.cnblogs.com/LenLi/p/3903641.html 结合博主实例,自己测试了一下,把数据改为3万行更明显!! 关于上一篇博客中提到的,在进行批量数据插入数据 ...
- 【C++进阶:STL常见性质】
STL中的常用容器包括:顺序性容器(vector.deque.list).关联容器(map.set).容器适配器(queue.stac) 转载自:https://blog.csdn.net/u0134 ...
- 使用spring配置类代替xml配置文件注册bean类
spring配置类,即在类上加@Configuration注解,使用这种配置类来注册bean,效果与xml文件是完全一样的,只是创建springIOC容器的方式不同: //通过xml文件创建sprin ...
- JS 弹出网页 (不显示地址栏,工具栏) 网页去掉地址栏
JS 弹出网页 (不显示地址栏,工具栏) 网页去掉地址栏 window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 基本语法: ...
- vue组件的watch属性
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- Java ——数组 选择排序 冒泡排序
本节重点思维导图 数组 public static void main(String[] args) { int a ; a=3; int[] b; b = new int[3];//强制开辟内存空间 ...
- django在线教育网站开发---需求分析
开发目录: django app设计 user model.py 编写 courses models.py 编写 -Course 课程基本信息 -Lesson 章节信息 -Video -视频 -Cou ...