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

时间:2013-07-29 12:53:33

标签: ruby-on-rails-3 apache passenger gitlab

我正在尝试设置gitlab,以便可以通过现有的apache服务器example.com/gitlab的子目录访问它。我试图使用乘客,因为这似乎是最容易设置的,但其他解决方案也是可以接受的。遗憾的是,gitlab使用单独的虚拟主机不适合我。

我的设置

在进行此设置时,我已关注gitlab setup guidepassenger documentation

我认为/etc/httpd/conf/httpd.conf中最相关的部分如下:

DocumentRoot "/home/.www"

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

apache的DocumentRoot包含gitlab公共目录的符号链接:

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

使用passenger-install-apache2-module脚本安装了Passenger,脚本输出的配置行包含在apache配置中。

我玩relative_url_root中的config/gitlab.yml;没有任何影响(根据文件中的注释判断,这种机制似乎不鼓励或弃用 - 避免它会很好)。

结果

访问example.com/gitlab时,我得到以下输出(纯文本文档):

Not Found: /

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

在我看来,没有必要启动任何puma服务器或类似的,所以我没有运行任何bundle exec rake ...命令来启动任何与轨道相关的生成上面的日志(我已经尝试过但是我不在这里输出输出,因为它看起来和我相同。)

有谁看到我做错了什么?

5 个答案:

答案 0 :(得分:9)

我认为Passenger不是为GitLab配置Apache的最简单方法。使用本地反向代理实际上更简单。

最新版本的GitLab(6.0)使用的是Unicorn,但与Puma几乎相同。

config/unicorn.rb文件中,发表评论listen指令并添加:

listen "127.0.0.1:9242"

在Apache配置中,您可以添加

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

重启Apache和GitLab,它应该可以工作。

答案 1 :(得分:5)

在官方支持的子目录中运行Gitlab,但工作正常(我目前正在运行实例)。我对Passenger一无所知,但这就是你使用unicorn和前端代理运行它的方式:

您需要在三个位置设置子目录(引用默认的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

我只是把ENV['RAILS_RELATIVE_URL_ROOT'] '/gitlab'放在unicorn.rb顶部的某处,因为没有“默认”的地方。

在此之后,您需要按照安装文档中的说明启动sidekiq(后台作业deamon)和unicorn(gitlab的webserver)。提供的init脚本运行得非常好。

最后,您需要设置apache webserver以将请求代理到后端unicorn实例。 mod_proxy配置为反向代理应该完成这项工作。 (Arthurs的答案在这一部分有更多细节)

如果您(或来自谷歌的某人)想要使用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;
}

答案 2 :(得分:4)

我做了以下操作,以便在Apache和LAMP环境的子目录中提供gitlab 6.2.2:

启用以下apache模块:

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

直接从文档中执行以下操作:

# 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"
/etc/apache2/mod-available/proxy.conf中的

ProxyRequests On
ProxyPreserveHost on
<Proxy *>
  AddDefaultCharset off
  Order deny,allow
  Allow from all 
  AllowOverride All
</Proxy>
/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

答案 3 :(得分:0)

user1258056's post上的更新:

在最近发布的Gitlab(我使用10.0.3)中,建议的解决方案导致资产未加载(错误401:未授权)

要解决此问题,请在 /etc/gitlab/gitlab.rb 中添加以下行:

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

更改 /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

这会导致资产请求被分派到Workhorse组件(端口8181),而其他请求则通过通常的路径(端口8081)

答案 4 :(得分:-2)

我使用gitlab&amp; nginx的。 在subdir中使用gitlab有很多问题(或bug)。 我使用gitlab.example.com(易于配置,易于记忆),而不是example.com/gitlab。