咨询热线:4006-75-4006

售前:9:00-23:30    备案:9:00-18:00    技术:7*24h

如何设置让nginx代理本地apache服务

2017-02-01 03:23:44 7891次

1.apache监听非80端口,并且配置的站点可访问.

nginx监听80端口

在nginx.con中引入proxy_apache.conf

include proxy_apache.conf

2.建立proxy_apache.conf文件内容如下

upstream localhost1 

  {

      server 127.0.0.1:8089;

  }

  

  upstream localhost2 

  {

     server 127.0.0.1:8088;

 } 

 server 

 {

     listen       80;

     server_name  www.landui.com;     

     location / 

     {

         proxy_pass      http://www.landui.com; #转发到上边定义的localhost2代理中去

         proxy_redirect          off;

         proxy_set_header        Host $host;

         proxy_set_header        X-Real-IP $remote_addr;

         proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

         proxy_set_header         X-Scheme $scheme;

     }

 }    

 server 

 {

     listen       80;

     server_name  www.landui.com;

         

     location / 

     {

         proxy_pass      http://www.landui.com; #转发到localhost1代理 

         proxy_redirect          off;

         proxy_set_header        Host $host;

         proxy_set_header        X-Real-IP $remote_addr;

         proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

     }

 }

 a)请求 example1 时


URI为/abc开头的转发到上边定义的localhost1代理,其余的URI请求转到localhost2代理


b).请求 example2 时

将所有请求转发到localhost1代理

c).配?中的proxy_set_header 是将nginx得到的请求信息(头信息等等)复制一份给代理服务器

d).nginx指令要有分号结尾,监听多个域名时,域名间用空格隔开后再以分号结尾

最后

在Apache中监听apache.conf中localhost1,localhost2两个代理指定的域名+端口 或 ip+端口,并作相应的配置

nginx 和 Apache重启后浏览器里访问试试

首页
最新活动
个人中心