Skip to content

Instantly share code, notes, and snippets.

@efinal
Created February 19, 2014 14:57
Show Gist options
  • Save efinal/9093723 to your computer and use it in GitHub Desktop.
Save efinal/9093723 to your computer and use it in GitHub Desktop.
Deploy gitlab with apache2 and unicorn in another port
#1, reference
https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/web-server/apache/gitlab-apache2.4.conf
http://serverfault.com/questions/512527/gitlab-with-apache-proxy
i created the following vhost configuration
#2, modify /home/git/gitlab/config/unicorn.rb:
comment the line like which listen through the socket and make sure it's listening through tcp port
# listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64
listen "localhost:20000", :tcp_nopush => true"
here I'm using 20000 as the port as 8080 has been taken by Tomcat already
#3, !important!, modify /home/git/gitlab/config/unicorn.rb:
change the 'timeout' value to a larger value, e.g. 300, which means 300s
it needs quite a long time for first time access, otherwise you will end up with timeout in unicorn worker process.
(the error message can be checked in /home/git/gitlab/log/unicorn_stderr.log)
from the web you will see 'proxy error' 'no response from /users/sign_in' etc.
reference:http://radiumblue.net/blog/2013/01/18/unicorn-error-gitlab-configuration/
#4, restart gitlab and apache2
sudo service gitlab restart
sudo service apache2 restart
This configuration has been tested on GitLab 6.5.0
#Note this config assumes unicorn is listening on default port 20000.
#Module dependencies
# mod_rewrite
# mod_proxy
# mod_proxy_http
<VirtualHost *:80>
ServerName git.xxx.com
ServerSignature Off
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:20000/
<Location />
# New authorization commands for apache 2.4 and up
# http://httpd.apache.org/docs/2.4/upgrading.html#access
Order allow,deny
Allow from all
ProxyPassReverse /
</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
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://localhost:20000%{REQUEST_URI} [P,QSA]
# needed for downloading attachments
DocumentRoot /home/git/gitlab/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 503 /deploy.html
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
ErrorLog /var/www/git.xxx.com/logs/error.log
CustomLog /var/www/git.xxx.com/logs/access.log common_forwarded
CustomLog /var/www/git.xxx.com/logs/access.log combined
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment