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的settings.xml配置详解
子节点详细介绍转载:http://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension 全局配置 ...
- 洛谷P1077 摆花——题解
题目传送 题目大意:有按顺序放的n种花,相同种类的花放一起,每种花最多放ai盆,共放了m盆花,求放花方案数. 求方案个数一般有以下思路:1.搜索:2.递推/动态规划:3.贪心:4.分治... 玄学估计 ...
- <知识整理>2019清北学堂提高储备D4
今天主要讲一下数学的知识. 一.进制转换: 十进制到k进制:短除法:顺除至0,逆序取余. k进制转十进制:乘权相加. 常见进制:四进制(对应2位二进制).八进制(对应3位二进制).十六进制(对应4位二 ...
- 给字体和元素加阴影text-shadow和box-shadow
1.语法: 对象选择器 {text-shadow:X轴偏移量 Y轴偏移量 阴影模糊半径 阴影颜色} 注:text-shadow可以使用一个或多个投影,如果使用多个投影时必须需要用逗号“,”分开. 2 ...
- Web 与 Node 基础
浏览器端发送请求(browser) 浏览器或者模拟发送 http 请求端 服务端处理请求(web) 服务器(使用 node ) 2.1. 使用 Forever 管理程序 2.2. 可以使用 PM2 代 ...
- UVALive 6859 Points (凸包)
Points 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/E Description http://7xjob4.com1.z ...
- 后端PHP框架laravel学习踩的各种坑
安装完laravel的ventor目录后出现“Whoops, looks like something went wrong.”这样的错误信息 打开config/app.php,打开debug为tru ...
- uva live 7635 National Bomb Defusing Squad
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- nginx + tomcat + memcached 做负载均衡及session同步
1.nginx配置 # For more information on configuration, see: # * Official English Documentation: http://n ...
- day41—JavaScript运动的停止条件
转行学开发,代码100天——2018-04-26 前面学过了JavaScript运动的两种常用情形:匀速运动与缓冲运动.在这两种运动的处理过程中最大的区别在于速度的处理和到达目标点的处理. 即本文需要 ...