Nginx反向代理新篇-使用location对多个URL做反向代理

1.原理

Nginx解析location/后面的字符串,配置不同的字符串匹配不同的URL进行反向代理。

2.nginx.conf配置文件

worker_processes  1;  
  
  
events {  
    worker_connections  1024;  
}  
  
  
http {  
    include       mime.types;  
    default_type  application/octet-stream;  
  
    sendfile        on;  
  
    keepalive_timeout  65;  
  
    server {  
        listen       2016;  
        server_name  localhost;  
        location / {  
            root   html;  
            index  index.html index.htm;  
        }  
        location /yyxtManager {  
            proxy_pass http://10.56.6.13:6667/yyxtManager;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  
        location /jrtxManager {  
            proxy_pass http://10.56.6.13:6666/jrtxManager;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  
        location /hytpay {  
            proxy_pass http://10.56.6.13:5555/hytpay;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  
        location /wlgz {  
            proxy_pass http://10.56.6.13:4444/wlgz;  
            proxy_set_header   Host    $host;  
            proxy_set_header   X-Real-IP   $remote_addr;   
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
        }  
        error_page   500 502 503 504  /50x.html;  
        location = /50x.html {  
            root   html;  
        }  
    }  
} 

  

posted @ 2017-06-28 13:51  年少的你如此美丽  阅读(1357)  评论(0编辑  收藏  举报