简体   繁体   English

Gitlab在一个带有apache和乘客的子目录中

[英]Gitlab in a subdirectory with apache and passenger

I'm attempting to set up gitlab so that it is accessible through a subdirectory of an existing apache server, example.com/gitlab , for example. 我正在尝试设置gitlab,以便可以通过现有的apache服务器的子目录访问它,例如example.com/gitlab I am trying to use passenger, as this seems to be the easiest to set up, but other solutions would also be acceptable. 我试图使用乘客,因为这似乎是最容易设置的,但其他解决方案也是可以接受的。 Using a separate virtual host for gitlab is unfortunately not an option for me. 遗憾的是,为gitlab使用单独的虚拟主机不是我的选择。

My Setup 我的设置

In setting this up, I have followed the gitlab setup guide and the passenger documentation . 在设置时,我遵循了gitlab设置指南乘客文档

I believe the most relevant parts of /etc/httpd/conf/httpd.conf are the following: 我相信/etc/httpd/conf/httpd.conf中最相关的部分如下:

DocumentRoot "/home/.www"

# gitlab config
RackBaseURI /gitlab
<Directory "/home/.www/gitlab">
    Options -MultiViews
</Directory>

The DocumentRoot of apache contains a symlink to the gitlab public directory: Apache的DocumentRoot包含gitlab公共目录的符号链接:

$ ls -l /home/.www
lrwxrwxrwx  1 root  http    23 Jul 29 12:35 gitlab -> ../gitlab/gitlab/public

Passenger was installed using the passenger-install-apache2-module script, and the config lines output by the script are included in the apache config. 使用passenger-install-apache2-module脚本passenger-install-apache2-module Passenger,脚本输出的配置行包含在apache配置中。

I have played with the relative_url_root in config/gitlab.yml ; 我打与relative_url_rootconfig/gitlab.yml ; that did not have any effect (judging from the the comments in the file, this mechanism seems to be discouraged or deprecated---it would be nice to avoid it). 这没有任何影响(根据文件中的注释判断,这种机制似乎是不鼓励或弃用的 - 避免它会很好)。

Results 结果

When accessing example.com/gitlab , I get the following output (a plain text document): 访问example.com/gitlab ,我得到以下输出(纯文本文档):

Not Found: /

Apache's logs indicate that passenger has started, but that at least favicon.ico is being requested from the document root, when it should be be requested from the subdirectory as /gitlab/favicon.ico : Apache的日志表明乘客已经启动,但至少要从文档根目录中请求favicon.ico ,当应该从子目录中请求/gitlab/favicon.ico

[ 2013-07-29 14:14:12.1029 2037/7f3502e1e740 agents/HelperAgent/Main.cpp:597 ]: PassengerHelperAgent online, listening at unix:/tmp/passenger.1.0.2033/generation-0/request
[ 2013-07-29 14:14:12.1150 2043/7fa24dbf3740 agents/LoggingAgent/Main.cpp:330 ]: PassengerLoggingAgent online, listening at unix:/tmp/passenger.1.0.2033/generation-0/logging
[ 2013-07-29 14:14:12.1154 2034/7ff20a0cb740 agents/Watchdog/Main.cpp:635 ]: All Phusion Passenger agents started!
[Mon Jul 29 14:14:12 2013] [notice] Digest: generating secret for digest authentication ...
[Mon Jul 29 14:14:12 2013] [notice] Digest: done
[ 2013-07-29 14:14:13.0297 2057/7f5380ee3740 agents/Watchdog/Main.cpp:452 ]: Options: { 'analytics_log_user' => 'nobody', 'default_group' => 'nobody', 'default_python' => 'python', 'default_ruby' => '/usr/bin/ruby', 'default_user' => 'nobody', 'log_level' => '0', 'max_instances_per_app' => '0', 'max_pool_size' => '6', 'passenger_root' => '/usr/lib/ruby/gems/2.0.0/gems/passenger-4.0.10', 'pool_idle_time' => '300', 'temp_dir' => '/tmp', 'union_station_gateway_address' => 'gateway.unionstationapp.com', 'union_station_gateway_port' => '443', 'user_switching' => 'true', 'web_server_pid' => '2055', 'web_server_type' => 'apache', 'web_server_worker_gid' => '33', 'web_server_worker_uid' => '33' }
[ 2013-07-29 14:14:13.0367 2061/7f92eefef740 agents/HelperAgent/Main.cpp:597 ]: PassengerHelperAgent online, listening at unix:/tmp/passenger.1.0.2055/generation-0/request
[ 2013-07-29 14:14:13.0485 2067/7f4cc5205740 agents/LoggingAgent/Main.cpp:330 ]: PassengerLoggingAgent online, listening at unix:/tmp/passenger.1.0.2055/generation-0/logging
[ 2013-07-29 14:14:13.0490 2057/7f5380ee3740 agents/Watchdog/Main.cpp:635 ]: All Phusion Passenger agents started!
[Mon Jul 29 14:14:13 2013] [notice] Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.1e DAV/2 Phusion_Passenger/4.0.10 configured -- resuming normal operations
[ 2013-07-29 14:14:16.8354 2061/7f92eef2a700 Pool2/Spawner.h:738 ]: [App 2096 stdout] 
[ 2013-07-29 14:14:24.8814 2061/7f92eef2a700 Pool2/SmartSpawner.h:301 ]: Preloader for /home/.www/../gitlab/gitlab started on PID 2096, listening on unix:/tmp/passenger.1.0.2055/generation-0/backends/preloader.2096
[Mon Jul 29 14:14:25 2013] [error] [client 129.241.220.221] File does not exist: /home/.www/favicon.ico

It seems to me that it should not be necessary to start any puma server or similar, so I have not run any bundle exec rake ... commands to start anything rails-related when generating the logs above (I have tried that but I'm not including the output here as it seems identical to me). 在我看来,没有必要启动任何puma服务器或类似,所以我没有运行任何bundle exec rake ...命令启动任何rails相关生成上面的日志(我试过但我'我不包括这里的输出,因为它似乎与我相同)。

Does anyone see what I am doing wrong? 有谁看到我做错了什么?

I don't think that Passenger is the easiest way to configure Apache for GitLab. 我不认为Passenger是为GitLab配置Apache的最简单方法。 Using a local reverse proxy is actually more simple. 使用本地反向代理实际上更简单。

The lastest version of GitLab (6.0) is using Unicorn, but it almost the same with Puma. 最新版本的GitLab(6.0)使用的是Unicorn,但与Puma几乎相同。

In your config/unicorn.rb file, comment listen directive and add: config/unicorn.rb文件中,注释listen指令并添加:

listen "127.0.0.1:9242"

In your Apache configuration, you can then add 在Apache配置中,您可以添加

ProxyPass         /gitlab http://127.0.0.1:9242
ProxyPassReverse  /gitlab http://127.0.0.1:9242

Restart Apache and GitLab, and it should work. 重启Apache和GitLab,它应该可以工作。

Running Gitlab in a subdirectory is not officially supported, but works fine (I'm currently running an instance). 在官方支持的子目录中运行Gitlab,但工作正常(我目前正在运行一个实例)。 I don't know anything about Passenger, but this is how you run it using unicorn and a frontend proxy: 我对Passenger一无所知,但这是你使用unicorn和前端代理运行它的方式:

You need to set you subdirectory in three places (to cite the default gitlab.yml): 您需要在三个位置设置子目录(引用默认的gitlab.yml):

# Uncomment and customize the last line to run in a non-root path
# WARNING: This feature is no longer supported
# Note that three settings need to be changed for this to work.
# 1) In your application.rb file: config.relative_url_root = "/gitlab"
# 2) In your gitlab.yml file: relative_url_root: /gitlab
# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT']
#
relative_url_root: /gitlab

I just put the ENV['RAILS_RELATIVE_URL_ROOT'] '/gitlab' somewhere at the top in unicorn.rb, as there is no "default" place. 我把ENV['RAILS_RELATIVE_URL_ROOT'] '/gitlab'放在unicorn.rb顶部的某处,因为没有“默认”的地方。

After this, you need to start sidekiq (the background job deamon) and unicorn (the webserver for gitlab) as described in the installation documentation. 在此之后,您需要启动sidekiq(后台作业deamon)和unicorn(gitlab的webserver),如安装文档中所述。 The supplied init script works really well. 提供的init脚本非常有效。

Finally you need to setup your apache webserver to proxy requests to the backend unicorn instance. 最后,您需要设置apache webserver以将请求代理到后端unicorn实例。 mod_proxy configured as a reverse proxy should do the job. 配置为反向代理的mod_proxy应该完成这项工作。 (Arthurs answer has a bit more detail on this part) (Arthurs的答案在这一部分有更多细节)

If you (or someone comming from google) want to use nginx as a frontend proxy, this is the configuration I use: 如果您(或来自谷歌的某人)想要使用nginx作为前端代理,这是我使用的配置:

location /gitlab {
    alias /home/git/gitlab/public;

    access_log  /var/log/nginx/gitlab_access.log;
    error_log   /var/log/nginx/gitlab_error.log;

    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
}

# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://gitlab;

    access_log  /var/log/nginx/gitlab_access.log;
    error_log   /var/log/nginx/gitlab_error.log;
}

I did the following to get gitlab 6.2.2 available in a sub-directory with Apache and a LAMP environment: 我做了以下操作,以便在Apache和LAMP环境的子目录中提供gitlab 6.2.2:

enable the following apache modules: 启用以下apache模块:

sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod rewrite

right from the documentation, do the following: 从文档中,执行以下操作:

# 1) In your application.rb file: config.relative_url_root = "/gitlab"
# 2) In your gitlab.yml file: relative_url_root: /gitlab
# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"

in /etc/apache2/mod-available/proxy.conf: 在/etc/apache2/mod-available/proxy.conf中:

ProxyRequests On
ProxyPreserveHost on
<Proxy *>
  AddDefaultCharset off
  Order deny,allow
  Allow from all 
  AllowOverride All
</Proxy>

in /etc/apache2/apache2.conf: 在/etc/apache2/apache2.conf中:

ProxyPass         /gitlab/ http://127.0.0.1:8080/gitlab/
ProxyPassReverse  /gitlab/ http://127.0.0.1:8080/gitlab/
ProxyPass         /gitlab http://127.0.0.1:8080/gitlab
ProxyPassReverse  /gitlab http://127.0.0.1:8080/gitlab
ProxyPass         /assets http://127.0.0.1:8080/gitlab/assets
ProxyPassReverse  /assets http://127.0.0.1:8080/gitlab/assets

An update on user1258056's post : user1258056帖子的更新:

On recent releases of Gitlab (I'm using 10.0.3), the proposed solution leads to assets not being loaded (Error 401 : Not Authorized) 在最近发布的Gitlab(我使用的是10.0.3)中,建议的解决方案导致资产未加载(错误401:未授权)

To fix this, add the following lines in /etc/gitlab/gitlab.rb : 要解决此问题,请在/etc/gitlab/gitlab.rb中添加以下行:

unicorn['port'] = 8081
gitlab_workhorse['listen_addr'] ="127.0.0.1:8181"
gitlab_workhorse['listen_network'] = "tcp"

And change /etc/apache2/apache2.conf as follow : 并更改/etc/apache2/apache2.conf如下:

ProxyPass         /gitlab/assets/ http://127.0.0.1:8181/gitlab/assets/
ProxyPassReverse  /gitlab/assets/ http://127.0.0.1:8181/gitlab/assets/

ProxyPass         /gitlab/ http://127.0.0.1:8081/gitlab/
ProxyPassReverse  /gitlab/ http://127.0.0.1:8081/gitlab/
ProxyPass         /gitlab http://127.0.0.1:8081/gitlab
ProxyPassReverse  /gitlab http://127.0.0.1:8081/gitlab

This leads to assets request being dispatched to the Workhorse component (port 8181), while other requests go through the usual path (port 8081) 这导致资产请求被分派到Workhorse组件(端口8181),而其他请求通过通常的路径(端口8081)

I use gitlab & nginx. 我用gitlab和nginx。 use gitlab in subdir has many problems (or bugs). 在subdir中使用gitlab有很多问题(或bug)。 I use gitlab.example.com (easy to configure, easy to remember), not example.com/gitlab. 我使用gitlab.example.com(易于配置,易于记忆),而不是example.com/gitlab。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM