[SOLVED] Setting up Gitlab on Ubuntu 14.04 with Apache2 without owning a domain name


#1

Hello,I’m relatively new to all of this server stuff (I’ve been with Linux for a while, but on the desktop), just a heads up. Also a heads up, I’ve done many searches on how to do this with still no solution.

Recently, I’ve been interested in moving my web services off of the web and to my own server, and Gitlab has appealed to me as a self-hosted alternative to Gitlab. A while back, I installed ownCloud (a Dropbox alternative) on a repurposed netbook running Ubuntu Server 14.04, and that set itself up with Apache as its web server. More recently, I installed Wallabag, (a self-hosted Pocket/read-it-later alternative) also under Apache. I access this Apache server set up through my router via port-forwarding to ports 80 and 443.

However, when I install Gitlab-omnibus, it installs itself with nginx, so it appears to be incompatible with the existing Apache set up I have, and appears to require owning a domain name (which I don’t have an interest in doing). I tried following tutorials online at how to set up Gitlab under Apache but to no avail.

How can I get Gitlab to play nice with Apache and my router/port-forwarding set up? Do I have to do some special config to get Gitlab to run under Apache? Or do I have to find a way to make nginx to operate in parallel Apache?

Thanks in advance for any help!


Running Gitlab on a subdomain under Apache on Ubuntu
After enabling Apache (ubuntu 14.04) GitLab gives 502
Can't get Gitlab setup right on Ubuntu14.4 / Apache 2.4
#2

I brought back your post, why did you delete it in the first place? It’s pretty legit and others might benefit if you found any solution.


#3

I don’t know, I have sort of given up on installing Gitlab with my seemingly unique setup (no domain name) and I didn’t want anyone wasting their time replying to something that I wasn’t going to use because I’d given up. But I do suppose it is worth it to keep it around, just in case someone does know.


#4

No worries :smile:

If you ever feel to continue and include GitLab to your services, do let us know.

btw ever heard of project https://github.com/al3x/sovereign ?


#5

Thanks :smile:

I’d really like use Gitlab, don’t get me wrong, but I’m just having a tough time with the setup. If I could get over that hurdle, I’d definitely use it.

I’ve already found something that works like Sovereign-- ownCloud. It handles file sync, calendars, contacts, etc. But thanks for the suggestion!


#6

Erm, sovereign is a pack of hosted services, owncloud included.

So you reach all these services from the netbook only from within the internal network?

As for gitlab, you can use your own external web server and not the bundled nginx. See https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#using-a-non-bundled-web-server

If you find any difficulties let us know.


#7

Oh! I did not realize that’s what sovereign was (I was in class when I replied to your post, so I only gave the github page a cursory glance) I’ll have to give that a closer look at some point. It seems appealing…

As for how I access those services, I use port forwarding on my router (80 and 443 for apache with ownCloud, 4040 for subsonic, a music streaming service). So I can access them away from home, but not directly through the netbook. Hopefully that help page you sent works with that setup- I’ll get back to you on that after I have time to try it. Thanks for all your help!


#8

Ok, you have a static ip or are you using dynamic DNS? In any case, I guess you are reaching those services via a domain name. If that’s the case here’s some steps that might get you going:

In /etc/gitlab/gitlab.rb add:

external_url "http://gitlab.example.com:4554"
# Disable nginx
nginx['enable'] = false
# Give apache user privileges to listen to GitLab
web_server['external_users'] = ['www-data']

Then run sudo gitlab-ctl reconfigure.

Then add the apache vhost along with the others, taken from this repo, download https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/web-server/apache/gitlab-apache2.4.conf

The settings you need to replace are:

  • <VirtualHost *:80> - change the port to say 4554
  • ServerName gitlab.example.com - replace with the domain with which you reach from outside
  • ProxyPassReverse http://gitlab.example.com/ - replace with ProxyPassReverse http://yourdomain.com:4554/
  • Change to DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
  • Fix the log paths at the end of this conf

Then as you already know, add Listen 4554 to /etc/apache2/ports.conf and restart apache.

Documentation: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#using-a-non-bundled-web-server


#9

I use DNS on the router, although I do not access the services through a domain name; I use the IP of the router (for example, to get to owncloud, I type in 9.9.9.9/owncloud [No, my router IP is not 9.9.9.9, I’ve changed it for security[). Would that config work with that?


#10

Ok, I’ve gone ahead and tried those steps, but when I try to restart Apache I get some errors:

* Restarting web server apache2                                         [fail] 
* The apache2 configtest failed.
Output of config test was:
AH00112: Warning: DocumentRoot [/home/git/gitlab/public] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name,    using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(2)No such file or directory: AH02291: Cannot access directory '/var/log/httpd/logs/' for error log of vhost defined at /etc/apache2/sites-enabled/gitlab.conf:7
AH00014: Configuration check failed
Action 'configtest' failed.
The Apache error log may have more information.

I guess I could create the log directories, but what’s up with the DocumentRoot error? That I do not understand.

UPDATE: I’ve removed the log error, but I still don’t know where to direct DocumentRoot to. I’ve tried

/opt/gitlab/embedded/html

(I picked that because it has an index.html file in it), but when I go to load IP.ADDRESS:4554 I get a generic “The connection timed out” error. Any ideas?

UPDATE 2: I’ve found out that the public DocumentRoot is

/opt/gitlab/embedded/service/gitlab-rails/public

but I still get the time out error when I load it. Maybe I should just switch from apache to nginx…


#11

Crap I forgot about the documentroot, fixed in my post above.

As for the timeout, can you try and do what is told in this issue? https://gitlab.com/gitlab-org/gitlab-recipes/issues/25


#12

@axil

I have tried your suggestions but I am still unable to access GitLab via port 80 with Apache 2.4. Optimally I would like the URL to access GitLab to be http://mysite.example.com/gitlab (I don’t require HTTPS), but I see most of the configuration indicates that GitLab will be available at a subdomain, namely http://gitlab.mysite.example.com so that is how I have been trying to get things to work.

As I mentioned in the issue I created here I have Tomcat running on port 8080 so I have changed my unicorn port to 8081. Here are my config files. These are the only files I have changed. Note that

1.) All the places you used port 4554 in your example I used port 81.
2.) Anywhere that port 8080 was referenced I changed it to port 8081 because that is what I changed my unicorn port to.
3.) I didn’t change the VirtualHost statement in /etc/apache2/sites-enabled/000-default.conf as suggested in the comment at the top of /etc/apache2/ports.conf.

/etc/gitlab/gitlab.rb

# https://gitlab.com/gitlab-org/omnibus-gitlab/blob/629def0a7a26e7c2326566f0758d4a27857b52a3/README.md#configuring-the-external-url-for-gitlab
external_url 'http://mysite.example.com:81' # I have also tried http://gitlab.mysite.example.com and http://gitlab.example.com:81

# https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#tcp-ports-for-gitlab-services-are-already-taken
unicorn['port'] = 8081

#https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#storing-git-data-in-an-alternative-directory
git_data_dir "/mnt/tank/gitlab"

# https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#using-a-non-bundled-web-server
nginx['enable'] = false
web_server['external_users'] = ['www-data']

/etc/apache2/sites-available/gitlab.conf

#This configuration has been tested on GitLab 6.0.0 and GitLab 6.0.1
#Note this config assumes unicorn is listening on default port 8080.
#Module dependencies
#  mod_rewrite
#  mod_proxy
#  mod_proxy_http
<VirtualHost *:81>
  ServerName mysite.example.com # I have also tried gitlab.mysite.example.com
  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 />
    # New authorization commands for apache 2.4 and up
    # http://httpd.apache.org/docs/2.4/upgrading.html#access
    Require all granted

    ProxyPassReverse http://127.0.0.1:8081
    ProxyPassReverse http://mysite.example.com:81/ # I have also tried http://gitlab.mysite.example.com:81/ and have also tried dropping the trailing slash
  </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://127.0.0.1:8081%{REQUEST_URI} [P,QSA]

  # 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 503 /deploy.html

  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
  ErrorLog  /var/log/apache2/gitlab_error.log
  CustomLog /var/log/apache2/gitlab_forwarded.log common_forwarded
  CustomLog /var/log/apache2/gitlab_access.log combined env=!dontlog
  CustomLog /var/log/apache2/gitlab.log combined

</VirtualHost>

/etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
Listen 81
<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

#13

Progress!! I’ve done all that was instructed, and now (after fixing a stupid Ubuntu firewall problem-- me forgetting to allow connections to port 4554 on my machine) I get… an error 500. Although, that error is thrown by Gitlab… so that’s something. It says (quite vaguely) “We’re sorry, but something went wrong. Please contact your GitLab administrator if this problem persists.” Thoughts? (Yes, I’ve rebooted)


#14

Can you add TimeOut 600 in the gitlab vhost file? Also check the logs for any messages.


#15

That is not supported by the omnibus package at the moment. You’d have to install from sources manually for that to work.

Since you have a subdomain to run to, you don’t have to make apache listen to port 81. GitLab’s app server (unicorn) which serves the whole application listens to 8080 by default. That you changed to 8081 and that’s that. Now you have to tell apache that whenever you hit http://gitlab.example.com proxy the request to 127.0.0.1:8081 where GitLab listens.

So to sum up.

  1. You don’t have to use port 81, remove it from your files
  2. Change to unicorn['port'] = 8081 in gitlab.rb, which you did
  3. Change 8080 to 8081 in apache vhost

Make sure that the dns for the subdomain is configured correclty. Also I don’t get why you keep saying

mysite.example.com # I have also tried gitlab.mysite.example.com

As I mentioned, if the dns is set up correclty it should point to the IP of the machine that hosts GitLab. From there apache takes care to properly route the requests.

What does /var/log/apache2/gitlab_error.log say?


#16

And I have to say that I’ve been trying all the configurations prior to posting here :smile:


#17

I’ve had TimeOut 600 in the vhost file, and that hasn’t made a difference. Also, I checked the logs and found this in the error log repeated a few times:

[Sun May 03 00:03:25.620758 2015] [proxy:error] [pid 1619] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8080 (*) failed
[Sun May 03 00:03:25.696748 2015] [proxy_http:error] [pid 1619] [client 69.127.25.143:47742] AH01114: HTTP: failed to make connection to backend: 127.0.0.1

I’ve made sure that connections are allowed to port 8080 on my server, and that hasn’t made a difference. Is there something else I have to do? Thanks so much for your help thus far!

UPDATE: Well, thanks to the powers of deductive reasoning, I’ve figured out that the problem is caused by unicorn (because port 8080 is causing the problem). I’ve tried reinstalling ruby to no avail; when I run gitlab-ctl everything restarts fine except for unicorn, which times out. Investigating further…

UPDATE 2: It lives! After reinstalling ruby 2.1.3 and running a reconfigure, I can now get to the login screen. Now I need to figure out how to get my server to send me a confirmation email… Thanks so much once again!


#18

Glad you got it working, but care to elaborate on this? You were using the package, right? If so, ruby is bundled in it, no need for manual install.


#19

The server I’m running it on is using Ubuntu 14.04 LTS, which ships with Ruby version 1.9. I saw on some forum that Gitlab was designed to work with Ruby 2.0. I did use the package to install, however after installation the Ruby version was still at 1.9. So, using https://github.com/postmodern/ruby-install I managed to install Ruby 2.1.3 successfully, which got rid of the 500 error on the Gitlab page.

EDIT: While I’m here, is there anything you could direct me to to get email configuration working? I have set up a Gmail account to send email from and (I think) I’ve edited the configuration files correctly to use that email, but Gitlab just says it sent me an email to set up my account and yet I get nothing in my personal email inbox.


#20

Aha! You should remove system ruby completely then. GitLab uses its own bundled version.

Can you open a new topic? Lots of questions to be answered :smile: