10

There is a situation where firstly all current requests should work as they currently working for certain domain name. For example www.hello.com

A dynamic dns is going to point to the same static ip of www.hello.com server (somedomain.dnsdynamic.com ---> XXX.XXX.XXX.XXX)

All requests, both GET, POST, etc. to be proxied to another server with hostname finalserver.example.com. (note that this server does not have a static ip, so the hostname must be used)

Proxy should only work when the www.hello.com server gets a request with server name somedomain.dnsdynamic.com

Already tried keeping in mind this answer but failed, either getting 502 bad gateway or 404 page not found

1 Answers1

12

If i understand you correctly, you could try defining two Virtual Hosts :

  • one for www.hello.com that serves the local web server content

  • another for somedomain.dnsdynamic.com that proxies to finalserver.example.com

Something like this :

    server {
      listen       80;
      server_name  www.hello.com;
      root /var/www;
      index   index.html;
    }

    server {
      listen       80;
      server_name  somedomain.dnsdynamic.com;

      location / {
        proxy_pass  http://finalserver.example.com;
      }
    }
krisFR
  • 12,830
  • 3
  • 31
  • 40
  • Thanks! seems to work so far. Need to test more thorougly though. One thing that we had to change in order to make it work was to comment out this line `proxy_set_header Host $host;`. This was causing the 404 page not found error because backend server just happened to be configured to not accept any other host name! Lucky guess :) – George Pligoropoulos Mar 03 '14 at 15:05
  • @George Pligor Ok, let me know about your tests. Cheers – krisFR Mar 03 '14 at 15:52
  • @George So what about your tests ? if this actually solved your problem thanks in advance to mark it as "answered" – krisFR Mar 06 '14 at 12:48
  • You left the site?.. well the issue has been put on hold because of other more critical issue, but rest assured that I will come back at this answer. have a good one – George Pligoropoulos Mar 08 '14 at 17:12
  • @George Pligor What you mean ? i'm still here man :) – krisFR Mar 08 '14 at 17:13
  • Ok sure, you just have no username so I could not reply to you. Ok your solution worked awesomely thank you. I will include as a note that `root /var/www;` and `index index.html` are actually redundant for those who are not using php – George Pligoropoulos Mar 12 '14 at 11:45
  • Hi! could you expand your answer to both nginx and Apache ? and I can expand the question for consistency. Thank you – George Pligoropoulos Mar 30 '14 at 14:36
  • @George Pligor This is not the way this site works. You asked for nginx and you got an answer. Now, if you want the same for Apache, you have to post a new question. Cheers – krisFR Mar 31 '14 at 11:37
  • ok got it, no problem – George Pligoropoulos Mar 31 '14 at 11:44
  • Can a set up like this reduce load on server? I am getting 502 bad gateway on our servers on increased load. Both our domains are pointing to same uwsgi_server . Will this help in resolving the issue ? – Kishan Mehta Aug 18 '17 at 05:01