nginx配置反向代理

例子:
10.XX.16.11 通过域名fsp.ord.fsh.bXXXX.sh访问实际地址为10.32.XX.60:10310的应用服务

接口http://fsp.ord.fsh.blackXX.sh/fsh-ord-main/manager/pay/notifyNew
fsp.ord.fsh.blackXX.sh实际地址为10.32.XX.60:10310

 

①在10.32.XX.12 nginx服务器上配置域名文件
[root@pre132 conf.d]# pwd
/usr/local/nginx/conf/conf.d
[root@pre132 conf.d]# vi fsp.ord.fsh.blackXX.sh.conf
文件内容如下
upstream fsh_ord_pre {
server 10.32.XX.60:10310;
}
server {
listen 80;
server_name fsp.ord.fsh.blackXX.sh; 
#charset koi8-r;
access_log logs/fsp.ord.fsh.blackXX.sh.log main;
location /{
#root /opt/tuniu/www/;
#index index.html index.htm;
proxy_set_header Host $host;
proxy_pass http://fsh_ord_pre;
}}


说明
access_log logs/fsp.ord.fsh.blackXX.sh.log main;    ----访问该域名的日志文件
[root@pre132 conf]# tail ../logs/fsp.ord.fsh.blackXX.sh.log -f
10.32.16.11 - - [04/Mar/2019:21:17:10 +0800] "GET /fsh-ord-main/manager/pay/notifyNew HTTP/1.1" 400 5 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" "-" 10.32.XX.60:10310 400

日志中可以看到域名转发到了10.32.XX.60:10310 ,但是报了400
所以加上了proxy_set_header Host $host;
这是由于ord该应用是tomcat 8,HTTP11协议的坑,具体见https://gofinall.com/64.html

 

②reload nginx配置文件
[root@pre132 conf]# /usr/local/nginx/sbin/nginx -s reload


③在10.32.XX.11上配置域名指向ngin服务器
[root@pre130 tomcat_pay_npc_01]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.32.XX.11 pre130
10.32.XX.12 fsp.ord.fsh.blackXX.sh

你可能感兴趣的:(nginx配置反向代理)