在一个nginx中configuration两个不同的应用程序服务器?

我有两个不同的应用服务器,一个是我的自定义应用程序,另一个是CRM。 我的自定义应用程序将得到请求,它会请求crm服务器的一些数据,并在最后服务器的客户。 我有一个nginx正在处理crm,我想要与我的应用程序处理相同的nginx,并让这些应用程序之间进行通信。

我已经尝试了以下configuration

upstream example.net{ server 192.168.200.144:8080; # virtual machine web1 site server 192.168.200.143:8080; # virtual machine web2 site } upstream example-crm.net{ server 192.168.200.85:8080; # virtual machine web1 site server 192.168.200.86:8080; # virtual machine web2 site } server { listen 192.168.200.173; # public IP address of your server server_name example.net; server_name example-crm.net location / { proxy_pass http://example.net; proxy_pass http://example-crm.net; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; send_timeout 900; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 

但它不起作用。
为了使其更清楚,我画了一个解释场景的图表
在这里输入图像说明

图解释:

客户发送请求1在虚拟IP 192.168.200.173,nginx发送请求2到应用1服务器,应用1服务器向nginx发送请求3到应用2服务器,nginx发送请求4到应用2服务器,应用2发送请求5到nginx而nginx发送请求6给应用程序1,应用程序1执行其业务逻辑并发送请求7给nginx和nginx将请求8提供给客户。

任何build议?

你做错了。 它应该如何:

 server { listen 192.168.200.173; # public IP address of your server server_name example.net location / { proxy_pass http://example.net; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; send_timeout 900; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 192.168.200.173; # public IP address of your server server_name example-crm.net location / { proxy_pass http://example-crm.net; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; send_timeout 900; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 

阅读nginx进程请求: http : //nginx.org/en/docs/http/request_processing.html

简而言之,它会为这个IP地址find两个服务器,然后在HTTP请求中检查“主机”头,并在服务器中检查具有相应server_name的进程请求。