4

我的网络上有 2 台服务器:

一台 linux 机器 (192.168.0.2) 的网站在 service1.domain.com 的端口 8181 上侦听 一台 Windows 机器 (192.168.0.3) 的网站在 service2.domain.com 的端口 8080 上侦听

我想设置一个 nginx 反向代理,以便我可以像这样路由请求:

service1.domain.com --> 192.168.0.2:8181 with host header service1.domain.com

service2.domain.com --> 192.168.0.3:8080 with host header service2.domain.com

我尝试了以下配置:

### General Server Settings             ###

worker_processes  1;

events {
  worker_connections  1024;
}

### Reverse Proxy Listener Definition  ###

http {
 server {
  listen        80;
  server_name       service1.domain.com;
  location / {
   proxy_pass       http://192.168.0.2:8181;
   proxy_set_header     host service1.domain.com;
  }
 }
server {
  listen        80;
  server_name       service2.domain.com;
  location / {
   proxy_pass       http://192.168.0.3:8080;
   proxy_set_header     host service2.domain.com;
  }
 }
}

但这似乎不起作用?

有什么明显的东西表明我在这里可能做错了吗?

4

1 回答 1

5

这对我来说很好:

http {
    server {
        listen        80; 
        server_name       service1.domain.com;
        location / { 
            proxy_pass       http://192.168.0.2:8181;
            proxy_set_header   host  service1.domain.com
        }   
    }
    server {
        listen        80; 
        server_name       service2.domain.com;
        location / { 
            proxy_pass       http://192.168.0.3:8080;
            proxy_set_header     host service2.domain.com;
        }   
    }
}

试试?

于 2013-09-10T12:31:59.150 回答