Apache : Nexus Sonar Jenkins Proxy

Neste post será apresentado como configurar um site para que as requisições cheguem em um determinado vhost e encaminhem para as ferramentas Nexus , Sonar e Jenkins.

 

1) Requisitos

 

Será necessário habilitar o mod_rewrite e mod_proxy no servidor Apache .

Verifique se está habilitado no /etc/httpd/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Restarte o Apache

systemctl restart httpd 
service httpd restart

 

2) Exemplos do vhost :

 

2.1) Configuração de um site como proxy para os serviços:

<VirtualHost *:80>
ServerName tools.example.com
DocumentRoot /var/www

<Directory /var/www>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 Allow from all
</Directory>
	
ProxyPass /hudson http://backend:8080/hudson/
ProxyPassReverse /hudson http://127.0.0.1:8080/hudson/

ProxyPass /nexus http://backend:8081/nexus
ProxyPassReverse /nexus http://backend:8081/nexus

ProxyPass /sonar http://backend:9000/sonar
ProxyPassReverse /sonar http://backend:9000/sonar
</VirtualHost>

 

2.1) Configuração do vhost como “multihost” :

<VirtualHost *:80>

ServerAlias *.jenkins.example.com
ServerName jenkins.example.com
#Sonar
ServerAlias sonar.example.com
ServerAlias *.sonar.example.com
#Nexus
ServerAlias nexus.example.com
ServerAlias *.nexus.example.com


DocumentRoot /var/www
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
	
## Proxy and Rewrite setup 
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteOptions Inherit

### Jenkins
 RewriteCond %{HTTP_HOST} ^jenkins.example.com(:80)?$
 RewriteRule ^/$ http://backend:8080/jenkins/ [P]
 RewriteRule ^/jenkins(.*)$ http://backend:8080/jenkins$1 [P]
 ProxyPassReverse  /jenkins http://backend:8080/jenkins


### Sonar
  RewriteCond %{HTTP_HOST} ^sonar.example.com(:80)?$
 RewriteRule ^/$ http://backend:9000/sonar/ [P]
 RewriteRule ^/sonar(.*)$ http://backend:9000/sonar$1 [P]
 ProxyPassReverse  /sonar http://backend:9000/sonar


### Nexus
  RewriteCond %{HTTP_HOST} ^nexus.example.com(:80)?$
  RewriteRule /(.*) http://backend:8099/nexus/$1  [P]

</VirtualHost>