I have a VPS with directadmin and few other websites on it, i want to install gitlab without damaging other sites. currently tried but it will show up on all domains. it seems external_url
is ignored completely.
it took me a day to figure out how to do it and i'm gonna share it with others, hope it helps!
if you're a beginner like me you should know these two things:
1- all the configurations are in /etc/gitlab/gitlab.rb
2- every time you change gitlab.rb you have to run gitlab-ctl reconfigure
and gitlab-ctl restart
ok.. the problem is that gitlab is bundled with nginx by default and it will break your apache setup. in order to fix that.
1- open your gitlab.rb configuration file: nano /etc/gitlab/gitlab.rb
2- make sure your external_url is set correctly like: gitlab.your-domain.tld
3- find and set nginx['enable'] = false
, it's commented by default, remove # from the beginning of the line to uncomment.
4- find and set web_server['external_users'] = ['admin']
it's very important since directadmin is not using default apache user 'www-data'
5- find and set gitlab_workhorse['listen_network'] = "tcp"
6- and finally set gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"
OPTIONAL to set smtp server create an email account in your directadmin and then set it by updating following configurations:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "mail.domain.tld"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "gitlab@domain.tld"
gitlab_rails['smtp_password'] = "email_password_here"
gitlab_rails['smtp_domain'] = "domain.tld"
gitlab_rails['smtp_authentication'] = "plain"
gitlab_rails['smtp_enable_starttls_auto'] = false
now save the file and run gitlab-ctl reconfigure
then gitlab-ctl restart
in order changes take effect.
now you're gitlab is ready, all you have to do now is to create subdomain that you used ex: gitlab for your domain. after you created the subdomain in your directadmin go to Admin Level > Custom HTTPD Configurations click on your domain and paste the following text into the blank text area: (note that you should change gitlab.your-domain.tld to whatever you set for external_url in gitlab.rb:
ServerName gitlab.your-domain.tld
ServerSignature Off
ProxyPreserveHost On
# Ensure that encoded slashes are not decoded but left in their encoded state.
# http://doc.gitlab.com/ce/api/projects.html#get-single-project
AllowEncodedSlashes NoDecode
<Location />
Order deny,allow
Allow from all
#Allow forwarding to gitlab-workhorse
ProxyPassReverse http://127.0.0.1:8181
ProxyPassReverse http://gitlab.your-domain.tld/
</Location>
# Apache equivalent of nginx try files
# http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
# http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
RewriteEngine on
#Forward all requests to gitlab-workhorse except existing files like error documents
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} ^/uploads/.*
RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
# needed for downloading attachments
DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
#Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
ErrorDocument 404 /404.html
ErrorDocument 422 /422.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 503 /503.html
that's it! you should be able to use your gitlab setup now without breaking other sites on your server. hope it helps!