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

jos*_*inb 13 apache passenger ruby-on-rails-3 gitlab

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

我的设置

在设置时,我遵循了gitlab设置指南乘客文档.

我相信最相关的部分/etc/httpd/conf/httpd.conf如下:

DocumentRoot "/home/.www"

# gitlab config
RackBaseURI /gitlab
<Directory "/home/.www/gitlab">
    Options -MultiViews
</Directory>
Run Code Online (Sandbox Code Playgroud)

DocumentRoot阿帕奇包含一个符号链接到gitlab公共目录:

$ ls -l /home/.www
lrwxrwxrwx  1 root  http    23 Jul 29 12:35 gitlab -> ../gitlab/gitlab/public
Run Code Online (Sandbox Code Playgroud)

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

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

结果

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

Not Found: /
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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

有谁看到我做错了什么?

Art*_*hur 9

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

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

在您的config/unicorn.rb文件中,注释listen指令并添加:

listen "127.0.0.1:9242"
Run Code Online (Sandbox Code Playgroud)

在Apache配置中,您可以添加

ProxyPass         /gitlab http://127.0.0.1:9242
ProxyPassReverse  /gitlab http://127.0.0.1:9242
Run Code Online (Sandbox Code Playgroud)

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


Del*_*tor 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
Run Code Online (Sandbox Code Playgroud)

我只是把它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;
}
Run Code Online (Sandbox Code Playgroud)