我可以将一些确切的远程URL映射到具有不同端口的本地URL

时间:2016-02-01 21:26:55

标签: apache nginx proxy reverse-proxy remote-server

长话短说: 我们有远程开发服务器。其中包含几个Symfony2实例。与 example.com/page1 example.com/page2 一样,是具有不同应用程序的不同AWS实例。其中一个(即 / page1 )是我的责任。我能够远程和本地开发它。显然,本地是最快的方式,但是当整个应用程序在类似域下同时工作时,为什么最好远程开发这些原因列表。所以我想让example.com/page1引用我的本地实例,所以我不会在每个Cmd + S上通过FTP发送文件。

从Apache设置我可以将一些本地URL映射到Remote,使用ProxyPass

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

我需要的是完全相同的,反之亦然。

我有两个相同的远程和本地运行的Web应用程序。

远程https://example.com:33333/app/

本地http://localhost:22222/app/

我需要以这种方式运作:

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

将远程URL保留在浏览器地址栏中。

是否可以在我的结尾设置它(而不是从远程的ProxyPass)

可能是某些Chrome扩展程序或代理应用程序?

2 个答案:

答案 0 :(得分:4)

它并不那么简单,它与代理传递完全不同。

当用户输入' example.com'在他们的浏览器中 - 浏览器决定在哪里发送请求,你的nginx配置无论如何都没有效果。但是,浏览器将使用DNS做出决定,您可以干预它。

如果您可以控制用户DNS - 您可以覆盖example.com域,以便请求来到您的本地服务器。如果它只是您的本地计算机,您可以在/ etc / hosts中执行此操作。之后,它就像在nginx配置中的server_name标签中添加example.com一样简单。

另一种可能性是配置路由器,但我认为它不适合你。

答案 1 :(得分:0)

如果我理解你的要求,这是我一直在Nginx做的事情:

我将使用/和#34; _"转到我的Elasticsearch服务器(例如/ index / type / _search),因此我的整个域实际上是多个系统,从而统一了域名并降低了SSL证书的成本。

这是一个示例Nginx配置:

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