2012-11-05 35 views
6

Cấu hình nginx cho gitlab là:Làm thế nào để cấu hình nginx để phục vụ gitlabhq trên 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; 
    } 
} 

gì tôi nên thay đổi để phục vụ gitlab như một surURI, www.mysuperserver.com/gitlab

i đã thử nhiều thứ khác nhau, nhưng không có gì hoạt động cảm ơn

Trả lời

2

Kể từ Gitlab 5.3 bạn có thể cấu hình nó để chạy trong một suburi ra khỏi hộp bằng cách sử dụng tài liệu cài đặt chính thức.

Bỏ ghi chú dòng 8 của config/puma.rb: ENV [ 'RAILS_RELATIVE_URL_ROOT'] = "/"

Tương tự như vậy đối với dòng 23 trong config/gitlab.yml: relative_url_root:/

tôi didn 't phải sửa đổi cấu hình nginx của tôi ở tất cả cho nó để làm việc.

1

Bạn đã giải quyết vấn đề này chưa?

Nếu không, hãy thử cập nhật các chỉ thị location / tới:

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; 
} 

Nếu điều đó không làm việc, hãy dán một vài dòng cuối cùng của /var/log/nginx/gitlab_error.log.

+0

Tôi có một vấn đề tương tự với câu hỏi ban đầu, và tôi đã thử cách tiếp cận của bạn để giải quyết nó. Nhật ký lỗi của tôi không có bất kỳ mục nhập mới nào trong đó và có vẻ như điều này không giải quyết được vấn đề. Những gì tôi đang cố gắng làm là áp dụng đề xuất của bạn cho một cái gì đó như thế này: http://unicorn.bogomips.org/examples/nginx.conf. –

-1

cấu hình này hoạt động

# 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; 
    } 
} 

Và tôi đã có một liên kết tượng trưng xấu giữa nginx sẵn cấu hình và cấu hình được kích hoạt.

+0

Tôi gặp khó khăn khi thấy sự khác biệt giữa cấu hình và cấu hình trong câu hỏi của bạn (ngoại trừ tên máy chủ). Đâu là phần cho phép 'www.mysuperserver.com/gitlab'? – VonC

+0

Cấu hình trên dường như dành cho tên miền phụ. Câu trả lời của tôi, mặc dù chưa được kiểm tra, nên làm việc cho câu hỏi khi nó được hỏi, 'www.mysuperserver.com/gitlab'. Nếu có ai cố gắng, sẽ rất tốt nếu được xác nhận. – myanimal

3

Tôi đã biến thành công nó hoạt động trong url phụ.

  • làm theo hướng dẫn trong mã nguồn, như trong /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 
  • thay đổi các nginx cấu hình để phục vụ một suburi, plz tham khảo ví dụ của tôi dưới đây:

Điểm mấu chốt là root trong ngữ cảnh serveralias dưới location. Vui lòng tham khảo nginx pitfalls, nginx root note để biết thêm chi tiết.

# 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. bạn đã sử dụng phiên bản GitLab nào? Bạn đã thử nghiệm nó với url ssh đẩy/kéo? https url? – VonC

+0

nhánh '6-4-ổn định'. không ai phàn nàn về việc đẩy/kéo. chưa thiết lập url https. – Ace

2

Đối với các phiên bản cũ, ví dụ: gitlab 7.4.5, không có gitlab-git-http-server (gitlab-workhorse). Nhưng có một số giải pháp cho gitlab 7.4.5 để sử dụng suburi trong doc.

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 

Cấu hình gitlab 7.4.5 với các trang web khác sử dụng cùng một cổng và cùng một tên miền trong một cấu hình nginx hoặc tập tin cấu hình apache dường như vẫn là một thách thức. Tôi đã không nhận được điều này. Tôi có thể truy cập gitlab dưới dạng www.mydomain.com/gitlab, nhưng tôi không nhận được trang web khác của tôi trong thư mục gốc khác với www.mydomain.com. Nó nên được resoved bằng cách cấu hình nginx hoặc apache. Hy vọng những người quen thuộc với nginx hoặc apache có thể đưa ra một giải pháp.

Tham chiếu khác. Support installing GitLab in a relative URL path or sub directory #1950

EDIT
Nó hoạt động ngay bây giờ.

luồng lưu lượng truy cập đề xuất sử dụng www.example.com làm ví dụ tại đây.

www.example.com/gitlab truy cập gitlab.

www.example.com truy cập một trang web khác, ví dụ: blog của tôi.

bước:

  1. config/application.rb file: config.relative_url_root = "/ gitlab"
  2. config/gitlab.yml file: relative_url_root:/gitlab
  3. config/unicorn.rb: ENV [ 'RAILS_RELATIVE_URL_ROOT'] = "/ gitlab"
  4. ../gitlab-shell/config.yml: gitlab_url: "http://www.example.com/gitlab"
  5. copy lib/support/nginx/gitlab để gitlab.conf cho nginx và không sử dụng tài sản gzipping, loại bỏ khối sao ting với "location ~^/(assets)/"
  6. chạy: sudo -u git -H bó tài sản cào exec: precompile RAILS_ENV = sản xuất

url:

  1. config/tập tin gitlab.yml: host: example.com cổng: 80
  2. config/unicorn.rb: nghe "127.0.0.1:9095"
  3. ../gitlab-shell/config.yml: gitlab_url: http://www.example.com/gitlab

gitlab sẽ cho git hai cách tiếp cận:

  1. [email protected]: tạo mẫu project.git
  2. http://example.com/gitlab/sample-project.git

Tôi không sử dụng https.

Nếu bạn đã nhận:

Bạn có thể cấu hình config/gitlab.yml như host: example.com/gitlab. Chỉ cần xóa /gitlab.

tập tin cấu hình

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) tập tin cấu hình: Reference gitlab.conf cho gitlab 6.0.6 và gitlab-8.0-apache2.2.conf cho gitlab 8.0.0 trên 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> 
Các vấn đề liên quan