1

I work on a project where im supposed to run simultaneously GitLab and Redmine on the same virtual machine using apache2. I started to install omnibus-GitLab (documented here https://about.gitlab.com/installation/#ubuntu) and edited the gitlab.rb to make it usable with apache2 (documented here https://docs.gitlab.com/omnibus/settings/nginx.html#using-a-non-bundled-web-server). Gitlab worked (url = my_ip/gitlab) before the redmine installation but after this installation (documented here : http://www.redmine.org/projects/redmine/wiki/howto_install_redmine_on_ubuntu_step_by_step) GitLab return a 404 (redmine works well on url my_ip/redmine). The only thing I could figure out is that GitLab is working again when I disable the redmine vhost. Here is my vhost :

GitLab vhost (found here https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server/apache) :

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

</VirtualHost>

Redmine vhost (found here : http://www.redmine.org/projects/redmine/wiki/howto_install_redmine_on_ubuntu_step_by_step)

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        <Directory /var/www/html/redmine>
                RailsBaseURI /redmine
                PassengerResolveSymlinksInDocumentRoot on
        </Directory>
</VirtualHost>

The solution im trying to focus on is one and only conf file including both vhosts

dAdOuCx
  • 11
  • 2

1 Answers1

2

None of your VirtualHost directives contain a ServerName directive. This is very important when you want to work with name based virtual hosts.

Example for Gitlab

<VirtualHost *:80>
    ServerName gitlab.example.com
    ...
</VirtualHost>

and for Redmine

<VirtualHost *:80>
    ServerName redmine.example.com
    ...
</VirtualHost

The ServerName has to be the same as the domain you are connecting to. If you do not have a matching ServerName it will match with the first available VirtualHost.

More information about the name based virtual hosts can be found at https://httpd.apache.org/docs/2.4/vhosts/name-based.html.

Thorchy
  • 1,421
  • 13
  • 15
  • The reason is (sorry I forgot to mention it) that Im working on a virtual machine so i do not use the Server Name but the ip address instead – dAdOuCx May 17 '18 at 18:50
  • @dAdOuCx Add to your DNS `gitlab.example.com A 1.2.3.4` and use `http://gitlab.example.com` because this answer is all correct. Same for redmine. – kubanczyk May 17 '18 at 19:48
  • @dAdOuCx You want to connect to 2 different applications via 1 single IP? Would you settle for having to connect to http://1.2.3.4/gitlab and http://1.2.3.4/redmine ? – Thorchy May 18 '18 at 07:09
  • @Thorchy yes, exactly – dAdOuCx May 18 '18 at 11:08