0

I have two different app servers one is my custom application and other is CRM. My custom app will get request and it will request crm server for some data and at the end server the customer. I have one nginx which is handling the crm and I want the same nginx deal with my application and let those app communicate in between.

I have tried with the following config

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;
}
}

but it doesn't work.
to make it more clear i have drawn a diagram which explain the scenario
enter image description here

Diagram Explanation:

customer send request 1 on virtual IP 192.168.200.173, nginx send request 2 to app 1 server, app 1 server sends request 3 to nginx for app 2 server, nginx send request 4 to app 2 server, and app 2 send request 5 to nginx and nginx send request 6 to app 1 and app 1 performs its business logic and send request 7 to nginx and nginx serve the request 8 to the customer.

Any suggestion ?

  • You should have two different server with different server_name and proxy_pass. – Navern Aug 25 '15 at 13:17
  • It is not very clear what you are trying to achieve. For one thing, the IP addresses in your diagram do not match up with those in your configuration. Also in your diagram, both App 1 server and App 2 server are labeled with the same IP addresses. It is also unclear what "Request 1" through "Request 8" are. Please clarify. – Tilman Schmidt Aug 25 '15 at 13:22
  • @TilmanSchmidt I have just updated the diagram and its explanation, have a look now. – Waqas Aug 25 '15 at 13:36
  • It is still not clear. The IP addresses still do not match. I do not understand the relationship between requests 1 .. 8. Why should Nginx generate requests of its own? Why does it send a request to the user? Should some of these perhaps be labeled "reply" instead? Are some of these really the same request being forwarded? Please clarify. – Tilman Schmidt Aug 25 '15 at 13:51
  • yes you can say reply instead, request 8 is the end reply which will be served to the customer – Waqas Aug 25 '15 at 14:02
3

You are doing it wrong. How it should be:

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;
        }
}

Read how nginx process request: http://nginx.org/en/docs/http/request_processing.html

It short it will find two server for this IP address, then it will check "Host" header in HTTP request and process request in server which have corresponding server_name.

| improve this answer | |
  • if i want to send request example-crm.net how would I do it (using the virtual ip)? – Waqas Aug 26 '15 at 10:55
  • curl -H 'Host: example-crm.net' virtual_ip – Navern Aug 26 '15 at 11:14
  • Provide full output of command and how you do this. – Navern Aug 26 '15 at 11:20
  • it is working using curl, what should be the url for browser ? – Waqas Aug 26 '15 at 11:24
  • example-crm.net for example-crm.net, and example.net for example.net. – Navern Aug 26 '15 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.