2012-11-05 41 views
6

爲gitlab nginx的配置是:如何配置nginx的服務gitlabhq上SubURI

# GITLAB 
# Maintainer: @randx 
# App Version: 3.0 

upstream gitlab { 
    server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket; 
} 

server { 
    listen YOUR_SERVER_IP:80;   # e.g., listen 192.168.1.1:80; 
    server_name YOUR_SERVER_FQDN;  # e.g., server_name source.example.com; 
    root /home/gitlab/gitlab/public; 

    # individual nginx logs for this gitlab vhost 
    access_log /var/log/nginx/gitlab_access.log; 
    error_log /var/log/nginx/gitlab_error.log; 

    location/{ 
    # 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; 
    } 
} 

我應該改變什麼服務gitlab作爲surURI,www.mysuperserver.com/gitlab

我已經嘗試了很多不同的東西,但沒有任何工作 謝謝

回答

2

從Gitlab 5.3開始,您可以使用官方安裝文檔將它配置爲開箱即用。

配置/ puma.rb的取消註釋行8: ENV [ 'RAILS_RELATIVE_URL_ROOT'] = 「/」

類似地,對於在配置/ gitlab.yml線23: relative_url_root:/

我沒有根本不需要修改我的nginx配置就可以工作。

1

您是否已解決此問題?

如果沒有,嘗試更新location /指令:

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

如果還是不行,請貼的/var/log/nginx/gitlab_error.log最後幾行。

+0

我有一個類似的問題與原來的問題,我試圖解決它的方法。我的錯誤日誌中沒有任何新條目,並且看起來這並不能解決問題。我想要做的是將你的建議應用於這樣的東西:http://unicorn.bogomips.org/examples/nginx.conf。 –

-1

這種配置工作

# GITLAB 
# Maintainer: @randx 
# App Version: 3.0 

upstream gitlab { 
    server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket; 
} 

server { 
    listen 80;   # e.g., listen 192.168.1.1:80; 37.59.125.28: 
    server_name gitlab.<YOUR_DOMAIN>.com;  # e.g., server_name source.example.com; 
    root /home/gitlab/gitlab/public; 

    # individual nginx logs for this gitlab vhost 
    access_log /var/log/nginx/gitlab_access.log; 
    error_log /var/log/nginx/gitlab_error.log; 

    location/{ 
    # 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; 
    } 
} 

而且我有nginx的可配置和啓用配置之間的不良符號鏈接。

+0

我很難看到你的配置和你的問題之間的區別(服務器名稱除外)。允許「www.mysuperserver.com/gitlab」的部分在哪裏? – VonC

+0

上述配置似乎是針對子域的。我的回答雖然沒有經過檢驗,但應該按照它的要求解決問題,即「www.mysuperserver.com/gitlab」。如果有人嘗試過,最好能得到確認。 – myanimal

3

我已經成功地使它在subdir url下工作。

  • 跟隨在源代碼中的指令,像/home/git/gitlab/config/gitlab.yml
 
    # 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 four 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" 
    # To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production 
    # 
    relative_url_root: /gitlab 
  • 變化nginx的配置以服務suburi,PLZ請參考下面的示例所示:

關鍵點是serveralias下的root在下3210。有關更多詳情,請參閱nginx pitfalls,nginx root note

# default.conf for nginx 
upstream gitlab { 
    server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; 
} 
server { 
    listen  80; 
    server_name $YOUR_DOMAIN; 
    # other settings, especially root settings, like below 
    # root /usr/local/nginx/html; 
    location /gitlab { 
     # serve static files from defined root folder; 
     alias /home/git/gitlab/public; 

     # individual nginx logs for this gitlab vhost 
     access_log /var/log/nginx/gitlab_access.log; 
     error_log /var/log/nginx/gitlab_error.log; 

     # @gitlab is a named location for the upstream fallback, see below 
     try_files $uri $uri/index.html $uri.html @gitlab; 
    } 

    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_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

     proxy_pass http://gitlab; 
    } 
    # other locations' settings... 
} 
+1

+1。你使用的是什麼版本的GitLab?你用推/拉ssh url測試了嗎? https url? – VonC

+0

分支'6-4-穩定'​​。沒有人抱怨推/拉。尚未設置https網址。 – Ace

2

對於舊版本,例如,gitlab 7.4.5,沒有gitlab-git的-HTTP-服務器(gitlab-主力)。但是有一些解決方案讓gitlab 7.4.5在文檔中使用suburi。

config/application.rb

# 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/gitlab.yml

# 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 

配置gitlab 7.4。5與其他網站在nginx配置或apache配置文件中使用相同的端口和相同的域名似乎仍然是一個挑戰。我沒有得到這個。我可以通過訪問www.mydomain.com/gitlab來訪問gitlab,但是我沒有在www.mydomain.com的另一個根目錄下找到我的另一個網站。它應該通過配置nginx或apache來消除。希望熟悉nginx或apache的人可以給出解決方案。

其他參考文獻。 Support installing GitLab in a relative URL path or sub directory #1950

編輯
它現在。

stackoverflow建議使用www.example.com作爲示例。

www.example.com/gitlab訪問gitlab。

www.example.com訪問另一個網站,比如我的博客。

步驟:

  1. 配置/ application.rb中的文件:config.relative_url_root = 「/ gitlab」
  2. 配置/ gitlab.yml文件:relative_url_root:/ gitlab
  3. 配置/ unicorn.rb: ENV [ 'RAILS_RELATIVE_URL_ROOT'] = 「/ gitlab」
  4. ../gitlab-shell/config.yml:gitlab_url:"http://www.example.com/gitlab"
  5. 複製的lib /支持/ nginx的/ gitlab到gitlab.conf爲nginx的和不使用的資產gzipping,刪除塊星廷"location ~^/(assets)/"
  6. 運行:須藤-u的git -H捆綁EXEC耙資產:預編譯 RAILS_ENV =生產

的url:

  1. 配置/ gitlab.yml文件:主機:example.com端口:80
  2. 配置/ unicorn.rb:聽 「127.0.0.1:9095」
  3. ../gitlab-shell/config.yml:gitlab_url: http://www.example.com/gitlab

gitlab會給git的雙向訪問:

  1. [email protected]:樣品project.git
  2. http://example.com/gitlab/sample-project.git

我不使用HTTPS。

如果你有:

你可以配置config/gitlab.ymlhost: example.com/gitlab。只要刪除/gitlab

nginx的配置文件:

################################### 
##   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.example.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/example.gitlab_access.log; 
    error_log logs/example.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(2.2.9)的配置文件:參考gitlab.conf爲gitlab 6.0.6和gitlab-8.0-apache2.2.conf用於gitlab 8.0.0在Apache 2.2

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


    ServerAdmin [email protected] 
    DocumentRoot "/data/webapp/www/wordpress" 

    ServerName www.example.com 
    ServerAlias example.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.example.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.example.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/example.com_error.log 
    CustomLog logs/example.com_forwarded.log common_forwarded 
    CustomLog logs/example.com_access.log combined env=!dontlog 
    CustomLog logs/example.com.log combined 

</VirtualHost> 
相關問題