Apacheredirect到另一个端口

我已经挣扎了一段时间,肯定是做错了事情。

我在同一台机器上有apache服务器和JBoss服务器。 我想redirect到mydomain.com的stream量到JBoss localhost:8080 / example。 DNS目前是为mydomain.com设置的,当进入浏览器时它将直接进入端口80。

我的问题是,当某个域名到达apache(在本例中为“mydomain.com”)时,如何redirect到不同的端口?

<VirtualHost ip.addr.is.here> ProxyPreserveHost On ProxyRequests Off ServerName mydomain.com ProxyPass http://mydomain.com http://localhost:8080/example ProxyPassReverse http://mydomain.com http://localhost:8080/example </VirtualHost> 

更新build议 – 仍然不转发到端口8080

 <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName mydomain.com ServerAlias www.mydomain.com ProxyPass http://mydomain.com http://localhost:8080/example ProxyPassReverse http://mydomain.com http://localhost:8080/example </VirtualHost> 

您应该忽略ProxyPass和ProxyPassReverse中的域http://example.com ,并将其保留为/ 。 此外,您需要将example/结尾处的/留在redirect的位置。 另外,我在http://example.comhttp://www.example.com遇到了一些麻烦 – 只有www才能工作,直到我创build了ServerName http://www.example.com和ServerAlias example.com。 给以下一个去。

 <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName www.example.com ServerAlias example.com ProxyPass / http://localhost:8080/example/ ProxyPassReverse / http://localhost:8080/example/ </VirtualHost> 

我用下面的代码解决了这个问题:

 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName myhost.com ServerAlias ww.myhost.com ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost> 

我也用过:

 a2enmod proxy_http 

我想这样做,所以我可以从根域访问jenkins。

我发现我不得不禁用默认网站,以使其工作。 这正是我所做的。

 $ sudo vi /etc/apache2/sites-available/jenkins 

并将其插入到文件中:

 <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName mydomain.com ServerAlias mydomain ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ <Proxy *> Order deny,allow Allow from all </Proxy> </VirtualHost> 

接下来,您需要启用/禁用适当的网站:

 $ sudo a2ensite jenkins $ sudo a2dissite default $ sudo service apache2 reload 

希望它可以帮助别人。

通过试验和错误发现了这一点。 如果你的configuration指定了一个ServerName,那么你的VirtualHost指令将需要做同样的事情。 在以下示例中,awesome.example.com和amazing.example.com都将被转发到端口4567上运行的本地服务。

 ServerName example.com:80 <VirtualHost example.com:80> ProxyPreserveHost On ProxyRequests Off ServerName awesome.example.com ServerAlias amazing.example.com ProxyPass / http://localhost:4567/ ProxyPassReverse / http://localhost:4567/ </VirtualHost> 

我知道这并不完全回答这个问题,但是我把它放在这里,因为这是Apache端口转发的最高search结果。 所以我觉得有一天会有帮助的

如果你不必使用JBoss的代理服务器,mydomain.com:8080可以“暴露”到世界上,那么我会这样做。

 <VirtualHost *:80> ServerName mydomain.com Redirect 301 / http://mydomain.com:8080/ </VirtualHost> 

这可能是一个古老的问题,但这是我所做的:

在由apache加载的.conf文件中:

 <VirtualHost *:80> ServerName something.com ProxyPass / http://localhost:8080/ </VirtualHost> 

说明:监听本地机器端口80的所有请求。如果我请求“ http://something.com/somethingorother ”,请将该请求转发到“ http://localhost:8080/somethingorother ”。 这应该为外部访问者工作,因为根据文档,它将远程请求映射到本地服务器的空间。

我正在运行Apache 2.4.6-2ubuntu2.2,所以我不知道“-2ubuntu2.2”如何影响这个答案的更广泛的适用性。

您必须确保在服务器上启用代理。 您可以通过使用以下命令来完成此操作:

  a2enmod proxy a2enmod proxy_http service apache2 restart 

只需在你的apacheconfiguration中使用一个反向代理(直接):

 ProxyPass /foo http://foo.example.com/bar ProxyPassReverse /foo http://foo.example.com/bar 

看看这里如何使用mod的Apache文档

Apache支持基于名称的和基于IP的虚拟主机。 它看起来像你正在使用,这可能不是你所需要的。

我想你实际上是在尝试设置基于名称的虚拟主机 ,为此你不需要指定IP地址。

尝试<VirtualHost *:80>绑定到所有的IP地址,除非你真的想要基于IP的虚拟主机 。 如果服务器有多个IP地址,并且您想在不同的地址上提供不同的站点,则可能会出现这种情况。 最常见的设置是(我猜)基于名称的虚拟主机。

你需要2件事情:

  1. 添加ServerAlias www.mydomain.com到您的configuration
  2. 将Proxypass改为ProxyPassMatch ^(.*)$ http://localhost:8080/example$1 ,以防止mod_dir和尾部斜杠干扰。

所有这些都是通过虚拟服务器上的域名访问端口的绝佳见解。 不过请不要忘记启用虚拟服务器; 这可能会被注释掉:

 NameVirtualHost *:80 <Directory "/home/dawba/www/"> allow from all </Directory> 

我们在域sxxxx.com上使用Apache服务器运行WSGI,在端口6800上运行golang服务器。一些防火墙似乎阻止了使用端口的域名。 这是我们的解决scheme:

 <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName wsgi.sxxxx.com DocumentRoot "/home/dxxxx/www" <Directory "/home/dxxx/www"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> ScriptAlias /py/ "/home/dxxxx/www/py/" WSGIScriptAlias /wsgiprog /home/dxxxx/www/wsgiprog/Form/Start.wsgi </VirtualHost> <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName sxxxx.com ServerAlias www.sxxxx.com ProxyPass / http://localhost:6800/ ProxyPassReverse / http://localhost:6800/ </VirtualHost> 

我的Apache听2个不同的端口,

 Listen 8080 Listen 80 

我使用80时,我想要一个透明的URL,不要把端口后的URL有用的谷歌服务,不会允许本地URL?

但我使用8080内部开发,我使用端口作为“开发环境”的参考,

这也在ISPConfig中工作。 在网站列表中进入一个域,单击选项选项卡,添加这些行:;

 ProxyPass / http://localhost:8181/ ProxyPassReverse / http://localhost:8181/ 

然后去网站和wolaa :)这也是HTTPS协议。