Redirect sub domain to a container (Apache/Gitlab)

Hi !

I’ve an Apache container which redirect these sub domain : 1.example.com & 2.example.com.
These 2 sub domain are redirect to different website folder /www/1 /www/2 thanks to Apache vhost.

But now i installed a Gitlab container (port 8080), and i want to join it by gitlab.example.com (without the port).

How can i redirect gitlab.example.com to this container ?

Thank you ! Guiguir68

The bit you probably need is the Apache ProxyPass directive. Create a new virtual host and set it to proxy to the container.

1 Like

Thank you Dmaze ! You have guided me well !

In my case, this is my apache2/sites-availabled/gitlab.conf :

<VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName gitlab.example.com ServerAlias example.com ProxyPass / http://192.168.1.1:8080/ ProxyPassReverse / http://192.168.1.1:8080/ </VirtualHost>

And don’t forget…

sudo a2ensite gitlab sudo a2enmod proxy sudo a2enmod proxy_http sudo service apache2 restart

Thanks again !

Hi,

You could also use this to redirect subdomains to containers dynamically: https://github.com/jwilder/nginx-proxy.

This Nginx-based tool automatically redirects requests to the appropriate container (based on the given subdomain using the VIRTUAL_HOST container environment variable).

I wrote a tutorial about it: http://blog.florianlopes.io/host-multiple-websites-on-single-host-docker.

For your use case, you would simply run the nginx-proxy container (port 80) and run the GitLab container (whatever port you like, provided it is exposed) with the “VIRTUAL_HOST=gitlab.example.com” environment variable.

@flopes have you heard of anything similar for apache, I don’t want to add nginx if I dont have to, seems unnecessary complexity.

Hi lindsaymacvean,

I have not heard of anything similar using Apache, couldn’t find anything relevant too.