8

Long story short: We have remote dev server. Which contains several Symfony2 instances. Like example.com/page1 and example.com/page2 are different AWS instances with different applications. One of those (i.e. /page1) is my responsibility. And I am able to develop it remotely and locally. Obviously locally is fastest way, but there're list of reasons why it's better to develop remotely when whole applications work at once under similar domain. So I want to make example.com/page1 to refer to my local instance, so I don't send files via FTP every Cmd+S.

From Apache settings I can map some local URL to the Remote one, doing it with ProxyPass

ProxyPass /app/ http://example.com/app/

What I need, is exactly the same, but vice versa.

I have two the same web applications running remotely and locally.

Remote: https://example.com:33333/app/

Local: http://localhost:22222/app/

I need to get it work in this way:

  • https://example.com:33333/homepage/ -> https://example.com:33333/homepage/
  • https://example.com:33333/app/ -> http://localhost:22222/app/

Keeping the remote URL in Browser address bar.

Is that possible to set it up on my end (not from ProxyPass on remote side)

Probably some Chrome Extension, or Proxy Application?

Mak
  • 19,913
  • 5
  • 26
  • 32
  • it's not clear the context that you need this under; is this something you want to do on a local box for local use or showcase (e.g., willing to follow multiple copy-paste instructions), enterprise setting (want to MitM a bunch of people), or looking for a 100% automated extension specific to Google Chrome (and if so, please replace the apache and nginx tags). What exactly are you trying to accomplish? where exactly does the existing answer fall short? – cnst Feb 06 '16 at 22:46
  • @cnst, Let me describe the problem I'd like to resolve. We have remote dev server. Which contains several Symfony2 instances. like example.com/page1 and example.com/page2 are different aws instances with different applications. One of those (i.e. /page1) is my responsibility. And I am able to develop it remotely and locally. Obviously locally is fastest way, but there're list of reasons why it's better to develop remotely when whole applications work at once under similar domain. So I want to make example.com/page1 to refer to my local instance, so I don't send files via FTP every Cmd+S. – Mak Feb 11 '16 at 09:42

3 Answers3

5

It's not as simple as that, and it's completely different from proxy pass.

When user types 'example.com' in their browser - browser decides where to send the request, your nginx configuration has no effect whatsoever. Browser will, however, use DNS to make the decision and you can interfere with that.

If you have control over users DNS - you could overwrite example.com domain so that requests come to your local server instead. If it's your local machine only, you could do it in /etc/hosts. After that, it's as simple as adding example.com in server_name tag in the nginx configuration.

Another possibility is configuring the router but I assume it's not an option for you.

Denis Mysenko
  • 6,366
  • 1
  • 24
  • 33
  • 1
    hi! thank you for answer. Sounds like a good plan, but could you please share some specific example ? – Mak Feb 11 '16 at 09:49
0

If I understand your request correctly, this is something I do all the time in Nginx:

I'll have / go to my web server and anything with and "_" go to my Elasticsearch server (e.g. /index/type/_search), so my entire domain is actually multiple systems, thus unifying the domain name and lowering the cost of SSL certs.

Here's a sample Nginx config:

server {
    listen 10.1.40.2:80;

    #+ your example
    location ~ /app {
        #+ another server
        proxy_pass      http://10.1.40.11:80;
        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-Forwarded-Host $server_name;
    }

    #+ your example
    location ~ /homepage {
        #+ another server
        proxy_pass      http://10.1.40.10:80;
        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-Forwarded-Host $server_name;
    }

    location ~ /_ {
        #+ different port
        proxy_pass      http://127.0.0.1:9200;
        proxy_http_version 1.1;
        proxy_set_header Connection "Keep-Alive";
        proxy_set_header Proxy-Connection "Keep-Alive";
    }

    location / {
        proxy_pass      http://127.0.0.1:80;
        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-Forwarded-Host $server_name;
    }
}
David Betz
  • 377
  • 4
  • 17
0

How about using a "Charles proxy" application to use "Map Remote" Option in the settings to map a URL and rewrite it with something you want.

guru
  • 2,661
  • 1
  • 10
  • 4