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的更多相关文章

  1. nginx负载均衡(5种方式)、rewrite重写规则及多server反代配置梳理

    Nginx除了可以用作web服务器外,他还可以用来做高性能的反向代理服务器,它能提供稳定高效的负载均衡解决方案.nginx可以用轮询.IP哈希.URL哈希等方式调度后端服务器,同时也能提供健康检查功能 ...

  2. (转)nginx负载均衡(5种方式)、rewrite重写规则及多server反代配置梳理

    Nginx除了可以用作web服务器外,他还可以用来做高性能的反向代理服务器,它能提供稳定高效的负载均衡解决方案.nginx可以用轮询.IP哈希.URL哈希等方式调度后端服务器,同时也能提供健康检查功能 ...

  3. Nginx/Httpd反代tomcat配置

    在上一篇博客中,我们了解了tomcat的server.xml中各组件的用法和作用:其中对于tomcat连接器来说,它分三类,一类是http连接器,一类是https连接器,一类是ajp连接器:通常tom ...

  4. tomcat 反代配置

    tomcat反代可以基于nginx , http进行反代 反代服务器: 有两个网口  反代服务器一般有两块网卡一块处于外网,一块处于内网用于与后端服务器通信 tomcat 节点处于内网地址 1 tom ...

  5. 使用nginx做反代时遇到413 Request Entity Too Large的解决方法

    在使用nginx做反向代理的时候,被反代的系统在上传文件的时候遇到413 错误 :Request Entity Too Large 原因是nginx限制了上传文件的大小,在nginx中可以配置最大允许 ...

  6. nginx反代及后端web配置

    一.反代配置,proxy_pass指向的upstream需要在反代的nginx.conf中配置 server {access_log /home/nginx/front_access.log;erro ...

  7. Nginx反代MogileFS集群

    上一篇博文我们主要聊了下分布式文件系统MogileFS的组件以及部署使用,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13677279.html:今天我们主要 ...

  8. Nginx反代Mogilefs分布式储存示例

    一.分布式存储系统简介 随着信息技术不断的发展,给我们带来便利的同时,不断增加的数据量级.信息之间的连接关联越来越复杂.数据访问的并发量日益增加对I/O的要求越来越高.数据类型越来越复杂等难题也成为信 ...

  9. Nginx反代,后端一个IP绑定多个SSL证书,导致连接失败之解决方法:HTTPS和SNI扩展

    默认:SSL协议进行握手协商进行连接的时候,默认是不会发送主机名的,也就是是以IP的形式来进行https连接握手协商的,这就导致一个问题,当一台服务器上有多个虚拟主机使用同一个IP的时候, Nginx ...

随机推荐

  1. sh_04_qq号码

    sh_04_qq号码 # 1. 定义一个变量记录 QQ 号码 qq_number = " # 2. 定义一个变量记录 QQ 密码 qq_password = " # 注意:在使用解 ...

  2. 【PowerOJ1751&网络流24题】数字梯形问题(费用流)

    题意: 思路: [问题分析] 求图的最大权不相交路径及其变种,用费用最大流解决. [建模方法] 规则(1) 把梯形中每个位置抽象为两个点<i.a>,<i.b>,建立附加源S汇T ...

  3. Linux基础命令及使用帮助

    一.内部命令 内置命令(builtin):由shell程序自带的命令 help:查看内部命令 enable -n command 禁用某内部命令 enable -n 查看全部被禁用的命令 enable ...

  4. 使用visual studio配置和运行《opengl圣经》的第一个案例

    对vc++新手来说,想把opengl圣经里的教学案例运行起来还真不是一件容易的事情,而且并没有完整的操作流程教学,这里就总结一下吧: 先安装cmake,用于生成vs的工程文件,安装过程中选中“将目录添 ...

  5. 解决 UIAlterController 不居中问题

    最后更新:2017-06-30 现象描述 新公司做的解决的第一个bug 就是 UIAlterController 不居中,莫名其妙的飞出屏幕之外 找了很久的答案,最终在苹果论坛看到了相关的描述 We ...

  6. [CSP-S模拟测试]:树(树上上升序列+主席树+线段树)

    题目传送门(内部题78) 输入格式 第一行输入两个整数$n,q$,表示节点数和询问数. 第二行输入$n$个整数$w_i$,表示第$i$个点的智商. 第三行至第$n+1$行每行输入两个数$x,y$,表示 ...

  7. flex几种多列布局

    基本的等分三列布局 .container{ display: flex; width: 500px; height: 200px; } .left{ flex:1; background: red; ...

  8. git 指定从其他分支拉取commit

    git cherry-pick commit-id  (github 上的短号)

  9. optistruct线性求解一次二次单元应力位移比较

    通过分析比较10mm.5mm.3mm.1mm的网格模型, 网格越细密: 位移与应力均趋于恒定值(收敛): 一次与二次单元的应力区域一致: 一次与二次单元的位移相差11.3%,一次单元的位移小. 所用的 ...

  10. Gradle 编译加速

    参考:http://www.jianshu.com/p/200d55b4d40a http://blog.isming.me/2015/03/18/android-build-speed-up/ ht ...