我有一个Ubuntu 12.04服务器, Redmine已经安装在一个独立的apache(所有在/ opt / redmine下)。 我想在同一个系统上安装一个Jenkins实例,而不用修改现有的设置。 我想分别在sub.domain.com/redmine和sub.domain.com/jenkins下访问这两个服务。
我改变Redmines Apache监听端口8081而不是80,通过apt安装了一个额外的Apache,并设置代理'/ redmine'到localhost:8081 / redmine的虚拟主机。 到目前为止一切正常。 Redmine像以前一样可以访问。 但是,当我以同样的方式设置Jenkins时,Tomcat在端口8080上侦听,URL前缀“jenkins”和一个新的虚拟主机,Redmine停止工作,即得到了404。当我删除Jenkins虚拟主机时,再次。
这里是/ etc / apache2 / sites-available下的两个文件,我通过a2ensite / a2dissite启用/禁用。
pipe理平台:
<VirtualHost *:80> ServerAdmin [email protected] ServerName sub.domain.com ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPreserveHost off ProxyPass /redmine http://localhost:8081/redmine ProxyPassReverse /redmine http://localhost:8081/redmine </VirtualHost>
jenkins:
<VirtualHost *:80> ServerAdmin [email protected] ServerName sub.domain.com ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPreserveHost off ProxyPass /jenkins http://localhost:8080/jenkins ProxyPassReverse /jenkins http://localhost:8080/jenkins </VirtualHost>
我假设这些文件中的一个或两个都有问题。 我从Jenkins教程中复制了他们,它只假定了一个虚拟主机。 无论我在哪里寻找多个主机的mod_proxy解决scheme,我都会find将不同的端口映射到不同域的示例,即使用不同的ServerNames。 但那不是我想要的。 我必须使用RewriteEngine吗?
Apache根据HTTP主机头匹配虚拟主机。 由于主机名是相同的,无论客户端是否访问redmine或jenkins,都必须在相同的虚拟主机。
目前的configuration发生了什么事情,Apache正在确定哪个虚拟主机看到主机头就匹配。 因为'j'按照字母顺序排在'r'之前,所以它会优先考虑你的jenkins vhost文件,即使两者都匹配。
<Proxy>
指令已经内置了这个function!
你可以在一个虚拟主机中使用类似以下的东西来实现你的目标:
<VirtualHost *:80> ServerAdmin [email protected] ServerName sub.domain.com ProxyRequests Off <Proxy http://sub.domain.com/jenkins> Order deny,allow Allow from all ProxyPreserveHost off ProxyPass http://localhost:8080/jenkins ProxyPassReverse http://localhost:8080/jenkins </Proxy> <Proxy http://sub.domain.com/redmine> Order deny,allow Allow from all ProxyPreserveHost off ProxyPass http://localhost:8081/redmine ProxyPassReverse http://localhost:8081/redmine </Proxy> </VirtualHost>