Apache 作为 Nexus、Jenkins 和 Foreman 的代理(同一域、IP 和端口上的多个虚拟主机)

Apache 作为 Nexus、Jenkins 和 Foreman 的代理(同一域、IP 和端口上的多个虚拟主机)

我想配置 Apache 作为在同一台服务器上安装和运行的 Nexus、Jenkins 和 Foreman 的代理。

这是 Foreman 虚拟主机配置文件的示例,除了代理传递参数外,Nexus 和 Jenkins 的其他文件看起来非常相似。

LoadModule ssl_module modules/mod_ssl.so
NameVirtualHost *:443
<VirtualHost *:443>
  SSLEngine On
  SSLProxyEngine On
  SSLCertificateFile /etc/httpd/ssl/certs/ssl.crt
  SSLCertificateKeyFile /etc/httpd/ssl/keys/server.key

  ServerName management.domain.com

  <Proxy *>
     Order deny,allow
     Allow from all
  </Proxy>

  ProxyPass        /foreman http://127.0.0.1:3000/foreman
  ProxyPassReverse /foreman http://127.0.0.1:3000/foreman
  ProxyPassReverse /foreman http://management.domain.com/foreman

  ProxyRequests Off
  ProxyPreserveHost On

  ErrorLog /var/log/httpd/management.domain.com_foreman_error.log
  LogLevel warn
  CustomLog /var/log/httpd/management.domain.com_foreman_access.log combined
</VirtualHost>

问题在于 Apache 仅考虑一个配置文件,而忽略了其他两个文件,从而导致出现错误消息“该服务器上未找到所请求的 URL /jenkins/。”当我尝试访问 URL management.domain.com/jenkins 时

如何配置 Apache 以加载三个虚拟主机?谢谢

PS:Listen 指令在 httpd.conf 中声明(= 443)

答案1

如果您使用一个服务器名称,它不会按您想要的方式工作。您只需要将 3 个虚拟主机合并到一个虚拟主机中。例如

LoadModule ssl_module modules/mod_ssl.so
NameVirtualHost *:443
<VirtualHost *:443>
  SSLEngine On
  SSLProxyEngine On
  SSLCertificateFile /etc/httpd/ssl/certs/ssl.crt
  SSLCertificateKeyFile /etc/httpd/ssl/keys/server.key

  ProxyRequests Off
  ProxyPreserveHost On

  ServerName management.domain.com

  <Proxy *>
     Order deny,allow
     Allow from all
  </Proxy>

  ProxyPass        /foreman http://127.0.0.1:3000/foreman
  ProxyPassReverse /foreman http://127.0.0.1:3000/foreman
  ProxyPassReverse /foreman http://management.domain.com/foreman

  ProxyPass        /nexus http://127.0.0.1:3000/nexus
  ProxyPassReverse /nexus http://127.0.0.1:3000/nexus
  ProxyPassReverse /nexus http://management.domain.com/nexus

  ProxyPass        /jenkins http://127.0.0.1:3000/jenkins
  ProxyPassReverse /jenkins http://127.0.0.1:3000/jenkins
  ProxyPassReverse /jenkins http://management.domain.com/jenkins

相关内容