I have a gitlab server next to my web server running on my home network. On my web server I run Apache2 with some domains. One of them is example.com. Now my aim is that the user receives the gitlab login page when visiting something like example.com/gitlab or gitlab.example.com. Actually I do not care whether the redirection happens from a certain url or a subdomain. I've already tried quite much but nothing of this worked for me (probably I did it wrong all times).
I also read some related forum posts like
- Use apache virtual host to redirect a subdomain to internal ip preserving passed port
- Use Apache's Name Based Virtual Host to Redirect to Internal IP
- https://www.linuxquestions.org/questions/linux-server-73/apache-redirect-to-internal-server-919321/
- ...
But I didn't get anything up and running.
My default.conf is configured that it always redirects Port 80 to Port 443 (HTTPS).
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/
[...]
</VirtualHost>
So here is my example.com.conf before:
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com
SSLEngine on
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
</VirtualHost>
First I tried to redirect from a certain url. I added:
ProxyRequests Off
ProxyPass /gitlab http://192.168.0.115:80/
ProxyPassReverse /gitlab http://192.168.0.115:80/
This does not work completly but if I enter the url, I get "404 The requested URL /users/sign_in was not found on this server". '/users/sign_in' is the path of the login page of my gitlab so server, so at least something seems to work. Strange to me is that it works if I redirect the root directory to my internal IP:
ProxyRequests Off
ProxyPass / http://192.168.0.113:80/
ProxyPassReverse / http://192.168.0.113:80/
This works but now I can't access my actual website anymore.
Then I tried redirection from a subdomain. I added:
<VirtualHost *:443>
ServerName gitlab.example.com
ProxyPass / http://192.168.0.113/
ProxyPassReverse / http://192.168.0.113/
</VirtualHost>
But I receive "The website is unreachable". I don't even get the subdomain running.