【问题标题】:Gitlab in a subdirectory with apache and passengerGitlab 在带有 apache 和乘客的子目录中
【发布时间】:2013-07-29 12:53:33
【问题描述】:

我正在尝试设置 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 是使用passenger-install-apache2-module 脚本安装的,脚本输出的配置行包含在 apache 配置中。

我在config/gitlab.yml中玩过relative_url_root;没有任何效果(从文件中的 cmets 来看,这种机制似乎不鼓励或不赞成使用——最好避免它)。

结果

访问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 ... 命令来启动任何与 rails 相关的东西(我已经尝试过了,但我m 不包括此处的输出,因为它似乎与我相同)。

有人看到我做错了吗?

【问题讨论】:

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


    【解决方案1】:

    我不认为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,它应该可以工作了。

    【讨论】:

    • 如何使 URL 工作在子目录中运行?我按照开发人员的建议更改了 gitlab.yml、application.rb 和 unicorn.rb,而 apache 说“未找到:/”我尝试只更改 gitlab.yml 和 application.rb(不是 unicorn.rb),它使网站可访问,但登录时无法重定向。
    • 很难看出一条评论有什么问题。你应该打开你自己的问题。
    【解决方案2】:

    官方不支持在子目录中运行 Gitlab,但可以正常工作(我目前正在运行一个实例)。我对Passenger一无所知,但这是您使用独角兽和前端代理运行它的方式:

    你需要在三个地方设置你的子目录(引用默认的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(后台作业守护程序)和 unicorn(gitlab 的网络服务器)。提供的初始化脚本运行良好。

    最后,您需要设置您的 apache 网络服务器来代理对后端 unicorn 实例的请求。 mod_proxy 配置为反向代理应该可以完成这项工作。 (亚瑟的回答对这部分有更多的细节)

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

    【讨论】:

    • 我正在运行 GitLab 6.0,所以是的
    • 对我来说似乎不适用于 Gitlab 6.0,一直返回“未找到:/”。
    【解决方案3】:

    我执行以下操作以在 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
    

    【讨论】:

    • 我知道这里的8080unicorn 端口。有了这个配置,你在 gitlab.yml 中使用哪个端口?默认的80 ?
    【解决方案4】:

    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)

    【讨论】:

      【解决方案5】:

      我使用 gitlab 和 nginx。 在 subdir 中使用 gitlab 有很多问题(或错误)。 我使用 gitlab.example.com(易于配置,易于记忆),而不是 example.com/gitlab。

      【讨论】:

      • 我正在一个子目录中运行一个 gitlab 实例,我没有看到任何错误。您能否具体解释一下您的意思(除了缺乏官方支持)?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 2013-06-03
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 2014-11-01
      相关资源
      最近更新 更多