gitlab 7.4.5 relative url configuration

假定将配置好的 gitlab 7.4.5 使用 relative_url, gitlab 7.4.5 没有对应的 gitlab-git-http-server(gitlab-horse),但是文档里提供了使用relative_url的方法。
目标访问方法:

  • www.mydomain.com 访问默认的主目录页面,比如我自己的 blog
  • www.mydomain.com/gitlab 访问 gitlab

环境:

System information
System:         CentOS 6.7
Current User:   git
Using RVM:      no
Ruby Version:   2.1.2p95
Gem Version:    2.2.2
Bundler Version:1.11.2
Rake Version:   10.3.2
Sidekiq Version:2.17.0

GitLab information
Version:        7.4.5
Revision:       19d572e
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://gitlab.example.com
HTTP Clone URL: http://gitlab.example.com/some-project.git
SSH Clone URL:  git@gitlab.example.com:some-project.git
Using LDAP:     no
Using Omniauth: no

GitLab Shell
Version:        2.0.1
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/bin/git

gitlab配置:
经实验 gitlab.yml 的这里 host 需要设置为 mydomain.com,不能写成 mydomain.com/gitlab 这样结果显示为 git@mydomain.com:your-project.git 和 http://mydomain.com/gitlab/your-project.git ,后者中间的 gitlab/ 不是因为这里产生的,如果这里设置成 mydomain.com/gitlab 就会产生错误的结果:git@mydomain.com/gitlab:your-project.git 和 http://mydomain.com/gitlab/gitlab/your-project.git

gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    #host: localhost
    host: mydomain.com    
    port: 80 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
    https: false # Set to true if using HTTPS, see installation.md#using-https for additional HTTPS configuration details

 # WARNING: See config/application.rb under "Relative url support" for the list of
    # other files that need to be changed for relative url support
    # relative_url_root: /gitlab
    relative_url_root: /gitlab
    # Relative url support
    # Uncomment and customize the last line to run in a non-root path
    # WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this.
    # Note that following 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'] = "/gitlab"
    # 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"
    # 5) In lib/support/nginx/gitlab : do not use asset gzipping, remove block starting with "location ~ ^/(assets)/"
    #
    # To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
    #
    # config.relative_url_root = "/gitlab"
    config.relative_url_root = "/gitlab"

所以不要忘了 删除 location ~ ^/(assets)/

  • 还不要忘了改unicorn.rb
# WARNING: See config/application.rb under "Relative url support" for the list of
# other files that need to be changed for relative url support
#
# ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
  • 还有 gitlab-shell 的 config.yml
gitlab_url: http://www.mydomain.com/gitlab

最后不要忘了执行 bundle exec rake assets:precompile RAILS_ENV=production 重新编译assets


nginx配置:
对 nginx 的配置,可在代码里自带样例配置文件 lib/support/nginx/gitlab 的基础上进行修改,gitlab是用 server unix:/home/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0; 接收信息的

为了访问其它目录的网站,比如我的博客在主目录,在原来的配置文件里加入了,这样 www.mydomain.com 访问 nginx 的 html 目录下的页面,www.mydomain.com/gitlab 访问 gitlab

  root html;
  location /{
    #root html;
    index index.html index.htm;
  }

###################################
##         configuration         ##
###################################
##

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0;
}

## Normal HTTP host
server {
  #listen *:80 default_server;
  listen *:80 default_server;
  server_name www.mydomain.com; ## Replace this with something like gitlab.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  #root /home/git/gitlab/public;
  root html;
  location /{
    #root html;
    index index.html index.htm;
  }
  ## Increase this if you want to upload large attachments
  ## Or if you want to accept large git objects over http
  client_max_body_size 20m;

  ## Individual nginx logs for this GitLab vhost
  access_log  logs/mydomain.gitlab_access.log;
  error_log   logs/mydomain.gitlab_error.log;

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

    ## 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 passes the request to the upsteam (gitlab unicorn).
  location @gitlab {
    ## If you use HTTPS make sure you disable gzip compression
    ## to be safe against BREACH attack.
    # gzip off;

    ## https://github.com/gitlabhq/gitlabhq/issues/694
    ## Some requests take more than 30 seconds.
    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;

    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;

    proxy_pass http://gitlab;
  }

  ## Enable gzip compression as per rails guide:
  ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  ## WARNING: If you are using relative urls remove the block below
  ## See config/application.rb under "Relative url support" for the list of
  ## other files that need to be changed for relative url support
  #location ~ ^/(assets)/ {
  #  root /home/git/gitlab/public;
  #  #gzip_static on; # to serve pre-gzipped version
  #  expires max;
  #  add_header Cache-Control public;
  #}

  error_page 502 /502.html;
}

Apache配置:
gitlab 7.4.5 文档没有推荐 apache 配置文件,但是有两个旧版的,一个测试于 6.0.0 的 gitlab.conf,和另一个测试于 8.0.0 的 gitlab-8.0-apache2.2.conf, 前者更接近 7.4.5 的配置,后者是 apache 2.2 的配置,由于我用的是 apache 2.2.9,所以结合二者进行配置。

注意这个配置需要 apache 的 mod_proxy mod_proxy_http mod_rewrite,需要载入这几个模块
我这里 gitlab unicorn 监听 9095

注意:要把如下 rewrite 代码段

    RewriteEngine on
    #RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule .* http://127.0.0.1:9095%{REQUEST_URI}

放在 <location /gitlab> </location> 中间


#Module dependencies
#  mod_rewrite
#  mod_proxy
#  mod_proxy_http
<VirtualHost *:80>


  ServerAdmin admin@mydomain.com
  DocumentRoot "/data/webapp/www/wordpress"

  ServerName www.mydomain.com
  ServerAlias mydomain.com

  #ErrorLog "logs/wordpress-error_log"
  #CustomLog "logs/wordpress-access_log" common

    #SetEnv ZF2_PATH "/data/webapp/www/ZendFramework-2.3.3/library"
  SetEnv APPLICATION_ENV "development"
  <Directory /data/webapp/www/wordpress>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  #ServerName www.mydomain.com
  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 /gitlab>
    Order deny,allow
    Allow from all

    ProxyPassReverse http://127.0.0.1:9095
    ProxyPassReverse http://www.mydomain.com//

    RewriteEngine on
    #RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule .* http://127.0.0.1:9095%{REQUEST_URI} [P,QSA,NE]
  </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
  #  RewriteCond /code/gitlab/{REQUEST_FILENAME} !-f
  #  RewriteRule .* http://127.0.0.1:9095%{REQUEST_URI} [P,QSA,NE]

  # needed for downloading attachments
  #DocumentRoot /home/git/gitlab/public
  Alias /gitlab /home/git/gitlab/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 503 /deploy.html

  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
  ErrorLog  logs/mydomain.com_error.log
  CustomLog logs/mydomain.com_forwarded.log common_forwarded
  CustomLog logs/mydomain.com_access.log combined env=!dontlog
  CustomLog logs/mydomain.com.log combined

</VirtualHost>

这样 www.mydomain.com 访问 wordpress,www.mydomain.com/gitlab 访问 gitlab。

目前,可以运行,页面创建 project 没有问题,客户端 git push 没有问题。由于我对 nginx 和 apache 的配置都不熟,所以配置文件需要修改优化,望指教。

  1. how-to-configure-nginx-to-serve-gitlabhq-on-a-suburi
  2. gitlab-7-2-1-with-apache-server-instead-of-nginx
  3. Support installing GitLab in a relative URL path or sub directory #1950
  4. gitlab 从源码安装: [1] Distribution : CentOS 6.5 Minimal, GitLab version : 7.0 - 7.4, Web Server : Apache, Nginx, 中文版, [2] 7.4.5 对应 gitlab shell [3] 至写此文时最新的从源码安装官方文档
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值