Configure SonarQube with Apache on Linux
Most likely, if you are here it is because you have already installed SonarQube, configured it properly and as a last step you want to create a virtual host in apache to access it in a friendly way. If not, I invite you to review the following posts that will help you with the installation and configuration.
- SonarQube Installation
- Configure PostgreSQL in SonarQube
- Configure SonarQube to start as a service in Linux
Environment configuration
To perform the configuration that we will see later you need to enable the modules related to apache proxy. For this, you can use the a2enmod
utility from apache.
a2enmod proxy
a2enmod proxy_http
Virtual host configuration
To create the virtual host you must create the sonarqube.pleets.org.conf
file in sites-available
or wherever you have the virtual host path in the general apache configuration and paste the following content.
ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
ServerName sonarqube.pleets.org
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://sonarqube.mydomain.com/
ErrorLog /var/opt/sonarqube-8/logs/apache-error.log
CustomLog /var/opt/sonarqube-8/logs/apache-access.log common
</virtualhost>
To activate the site you must run the following command. As I say, everything will depend on the configuration, you may not need to do it.
a2ensite sonarqube.mydomain.com
To verify that everything is correct, you can run the configtest of apache.
apachectl configtest
If everything has gone well, you can load the new configuration with the following command.
systemctl reload apache2