在唯一的 Apache 服务器上运行 Redmine 和 Gitlab

在唯一的 Apache 服务器上运行 Redmine 和 Gitlab

我从事一个项目,需要同时运行GitLab 和 Redmine一样的虚拟机使用 apache2。我开始安装 omnibus-GitLab(记录在这里https://about.gitlab.com/installation/#ubuntu)并编辑了 gitlab.rb 以使其可用于 apache2(记录在这里https://docs.gitlab.com/omnibus/settings/nginx.html#using-a-non-bundled-web-server在安装 redmine 之前,Gitlab 可以正常工作(url = my_ip/gitlab),但在安装之后(记​​录在此处:http://www.redmine.org/projects/redmine/wiki/howto_install_redmine_on_ubuntu_step_by_step) GitLab 返回 404(redmine 在 url my_ip/redmine 上运行良好)。我唯一能弄清楚的是,当我禁用 redmine vhost 时,GitLab 又可以正常工作了。这是我的 vhost:

GitLab vhost(在此处找到)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(在这里找到: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>

我试图关注的解决方案是包含两个虚拟主机的唯一一个 conf 文件

答案1

您的 VirtualHost 指令均不包含ServerName指令。当您想要使用基于名称的虚拟主机时,这一点非常重要。

Gitlab 示例

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

对于Redmine

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

必须ServerName与您要连接的域相同。如果没有匹配的,ServerName它将与第一个可用的匹配VirtualHost

有关基于名称的虚拟主机的更多信息,请访问https://httpd.apache.org/docs/2.4/vhosts/name-based.html

相关内容