Gitlab on raspberry as subdirectory on apache

Hello,

I would like to bring to ownCloud parallel to gitlab on Apache .

Preconditions :

  • Raspberry pi 2
  • Domain with “no-ip”

My owncloud is a subdirectory of my root as mydomain.org/cloud. Can i use gitlab as mydomain.org/gitlab?

my previous actions :

  1. installation via Omnibus

  2. Adjustments in /etc/gitlab/gitlab.rb

    $external_url ‘http://mydomain/gitlab
    web_server[‘external_users’] = [‘www-data’]
    nginx[‘enable’] = false

3, creating a gitlab.conf in sites-available

# This configuration has been tested on GitLab 8.2
# Note this config assumes unicorn is listening on default port 8080 and
# gitlab-workhorse is listening on port 8181. To allow gitlab-workhorse to
# listen on port 8181, edit /etc/gitlab/gitlab.rb and change the following:
#
# gitlab_workhorse['listen_network'] = "tcp"
# gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"
#
#Module dependencies
# mod_rewrite
# mod_proxy
# mod_proxy_http
<VirtualHost *:80>
  ServerName mydomain.org/gitlab
  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

    #Allow forwarding to gitlab-workhorse
    ProxyPassReverse http://127.0.0.1:8181
    ProxyPassReverse http://mydomain.org/gitlab/
  </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

  #Don't escape encoded characters in api requests
  RewriteCond %{REQUEST_URI} ^/api/v3/.*
  RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]

  #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]

  # 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$
  ErrorDocument 404 /404.html
  ErrorDocument 422 /422.html
  ErrorDocument 500 /500.html
  ErrorDocument 503 /deploy.html

  # It is assumed that the log directory is in /var/log/httpd.
  # For Debian distributions you might want to change this to

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

What do differently I do?

Thanks for hints and help .

Does anyone have an idea or suggestion for me?

Hi,

Sorry for bumping this subject but I had the same problem and as I’ve managed to get a solution I decided to reply in case of someone is looking for a solution.

In my case the preconditions are more or less the same, I am running a CentOS 7 server using a “no-ip” domain with Apache running Nextcloud and Mediawiki with SSL.

Based in the instructions of the non bundled web server in /etc/gitlab/gitlab.rb I modified:

external_url 'https://mydomain/gitlab'                     # I am using SSL
gitlab_workhorse['listen_network'] = "tcp"               # Apache can only use http sockets 
web_server['external_users'] = ['apache']                # In CentOS the Apache user is apache
nginx['enable'] = false

Once we have run gitlab-ctl reconfigure, we have to configure Apache. For what I have look for most of the people is trying to use subfolder with VirtualHost but it looks like that is not possible. Then in order to get the subfolders I have use Alias and Location in the Apache’s default /etc/httpd/conf.d/sll.conf file:

<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot /var/www/html
ServerName <myNoIpDomain>:443
ServerAdmin webmaster@localhost

Header add Strict-Transport-Security: "max-age=15768000;includeSubdomains"

...

#  Gitlab
Alias /gitlab  /opt/gitlab/embedded/service/gitlab-rails/public

<Location /gitlab>
  # New authorization commands for apache 2.4 and up
  # http://httpd.apache.org/docs/2.4/upgrading.html#access
  Require all granted

  #Allow forwarding to gitlab-workhorse
  ProxyPassReverse http://127.0.0.1:8181
  ProxyPassReverse https://<myNoIpDomain>/gitlab

  # 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 /opt/gitlab/embedded/service/gitlab-rails/public/%{REQUEST_FILENAME} !-f [OR]
  RewriteCond %{REQUEST_URI} ^/uploads/.*
  RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]

  RequestHeader set X_FORWARDED_PROTO 'https'
  RequestHeader set X-Forwarded-Ssl on

  #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
</Location>
</VirtualHost>

With our conf file edited now we can restart Apache.

And as last step and as I am using CentOS with SELinux I have to grant permission to Apache to use the http sockets.

$ sudo setsebool -P httpd_can_network_connect=1

Now GitLab should be working but a least for me it will work with a small problem. I get a 404 error when I log in, in other to avoid this 404 error I have to introduce manually the <user>/admin in the url: https://<myNoIpDomain>/gitlab/<user>, after doing that everything is normal.

About this last problem for the moment my only clue is in the log /var/log/gitlab/gitlab-rails/production.log

Started GET "/gitlab/index.html" for <ip> at 2017-01-22 16:59:59 +0100
Processing by ApplicationController#route_not_found as HTML
  Parameters: {"unmatched_route"=>"index"}
Completed 404 Not Found in 570ms (Views: 143.5ms | ActiveRecord: 4.0ms)

If someone has a better solution will be nice to know.