How to proxy Gitlab nginx into Apache2?

May 10, 2014 10.6k views
So I have a few sites on my droplet already going through apache. I installed gitlab, and it just took over everything because nginx runs over everything. I was silly enough to install the omnibus package (https://www.gitlab.com/downloads/) not realizing that it was a very unordinary install. I have googled for days and came up with nothing, because apparently no one uses this type install! Basically, I want to have gitlab.mydomain.com go to the gitlab and everything else proxy to apache. I'm not entirely sure what information to include here (my configs etc), because I'm pretty much lost now, so please ask, and I will provide more information. So far I've tried so many different variations that I'm not even sure where I'm at anymore. This is driving me mad. Any information would be fantastic!
1 Answer
It's all slightly more complicated as the package provided by GitLab bundles a lot of things in /opt. They assume it will be the only thing running on the server, but it is still doable.

In "/var/opt/gitlab/nginx/etc/gitlab-http.conf" set the server name to gitlab.mydomain.com:


server {
listen *:80;
server_name gitlab.mydomain.com;
server_tokens off; # don't show the version number, a security best practice
root /opt/gitlab/embedded/service/gitlab-rails/public;


Then create a new server block that will forward other connections onto Apache:


server {
listen 80;

root /var/www/;
index index.php index.html index.htm;

server_name mydomain.com;

location / {
try_files $uri $uri/ /index.php;
}

location ~ \.php$ {

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;

}

location ~ /\.ht {
deny all;
}
}


Then in your Apache configuration, change the VirtualHost to listen on port 8080:


<VirtualHost 127.0.0.1:8080>


This article about using Nginx as a proxy for Apache should be helpful:

https://digitalocean.com/community/articles/how-to-configure-nginx-as-a-front-end-proxy-for-apache

There's also an article about installing GitLab from source. That might be a better option for you:

https://digitalocean.com/community/articles/how-to-set-up-gitlab-as-your-very-own-private-github-clone

Let us know how it goes!
by Nik van der Ploeg
GitLab provides a simple but powerful web based interface to your Git repositories a la GitHub. Only you can host it on your own cloud server, control access as you see fit, and repo size is limited only by how much storage space your server has. This tutorial will walk you through setting up a DigitalOcean VPS as a GitLab server.
  • Hello Andrew,

    Thank you for your clear instructions, I only have 2 questions though:

    1. we're aware that the gitlab-http.conf file is managed by gitlab-ctl, so, isn't it that our manual changes will get overwritten after gitlab-ctl reconfigure? Is there any way we can make this permanent? i.e. alter some ruby code somewhere? and;

    2. is there a way for us to restart nginx or we need to do gitlab-ctl reconfigure every time?

    Thank you much for the support and best regards,

  • You can also restart individual services with gitlab-ctl like:

    sudo gitlab-ctl restart nginx
    

    You can also make some Nginx configuration changes in /etc/gitlab/gitlab.rb Though, if you want to run GitLab along with other services on the same droplet, your best bet is probably to install GitLab from source rather than using the Omnibus installer.

    by Nik van der Ploeg
    GitLab provides a simple but powerful web based interface to your Git repositories a la GitHub. Only you can host it on your own cloud server, control access as you see fit, and repo size is limited only by how much storage space your server has. This tutorial will walk you through setting up a DigitalOcean VPS as a GitLab server.
  • Update: Hi! Just wanted to leave a quick update. GitLab has been adding more and more support for advanced configurations. You can now disable the bundled Nginx completely or inject custom directive. See this doc for more information.

Have another answer? Share your knowledge.