[英]How to configure nginx to serve gitlabhq on a SubURI
The nginx configuration for gitlab is: gitlab的nginx配置是:
# 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;
}
}
What should i change to serve gitlab as a surURI, www.mysuperserver.com/gitlab 我应该改变什么来作为surURI服务gitlab,www.mysuperserver.com / gitlab
i've tried many different things, but nothing worked thanks 我尝试了很多不同的东西,但没有任何效果谢谢
I've successfully made it working under a subdir url. 我已经成功地在子网址下工作了。
/home/git/gitlab/config/gitlab.yml
/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
The key point is the root
under context server
and alias
under location
. 关键点是上下文
server
下的root
和location
下的alias
。 Plz refer to nginx pitfalls , nginx root note for more details. Plz参考nginx陷阱 , 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...
}
As of Gitlab 5.3 you can configure it to run in a suburi out of the box using the official installation document. 从Gitlab 5.3开始,您可以使用官方安装文档将其配置为在开箱即用的suburi中运行。
Uncomment line 8 of config/puma.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/" 取消注释config / puma.rb的第8行:ENV ['RAILS_RELATIVE_URL_ROOT'] =“/”
Similarly for line 23 in config/gitlab.yml: relative_url_root: / 类似于config / gitlab.yml中的第23行:relative_url_root:/
I didn't have to modify my nginx config at all for it to work. 我没有必要修改我的nginx配置才能工作。
For old versions, for example, gitlab 7.4.5 , there is no gitlab-git-http-server (gitlab-workhorse). 对于旧版本,例如gitlab 7.4.5,没有gitlab-git-http-server(gitlab-workhorse)。 But there are some solutions for gitlab 7.4.5 to use suburi in the doc.
但是gitlab 7.4.5有一些解决方案可以在doc中使用suburi。
config/application.rb 配置/ 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 配置/ 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
Configuring gitlab 7.4.5 with other website using same port and same domain name in a nginx configuration or apache configuration file seems still a challenge. 在nginx配置或apache配置文件中使用相同端口和相同域名的其他网站配置gitlab 7.4.5似乎仍然是一个挑战。 I did not get this.
我没有得到这个。 I can access gitlab as www.mydomain.com/gitlab , but I did not get my another website in another root directory with www.mydomain.com.
我可以访问gitlab作为www.mydomain.com/gitlab,但我没有将我的另一个网站放在www.mydomain.com的另一个根目录中。 It should be resoved by configure nginx or apache.
它应该通过配置nginx或apache来解决。 Hope people who are familiar with nginx or apache can give a solution.
希望熟悉nginx或apache的人可以提供解决方案。
Other references. 其他参考。 Support installing GitLab in a relative URL path or sub directory #1950
支持在相对URL路径或子目录#1950中安装GitLab
EDIT 编辑
It works now. 它现在有效。
stackoverflow suggest to use www.example.com as example here. stackoverflow建议以www.example.com为例。
www.example.com/gitlab access gitlab. www.example.com/gitlab访问gitlab。
www.example.com access another website, say, my blog. www.example.com访问另一个网站,比如我的博客。
Steps: 脚步:
"http://www.example.com/gitlab"
"http://www.example.com/gitlab"
"location ~^/(assets)/"
"location ~^/(assets)/"
开头的块 Urls: 网址:
http://www.example.com/gitlab
http://www.example.com/gitlab
gitlab will give git two way to access: gitlab会给git两种访问方式:
I am not using https. 我没有使用https。
If you got: 如果你有:
You might configure config/gitlab.yml
as host: example.com/gitlab
. 您可以将
config/gitlab.yml
配置为host: example.com/gitlab
。 Just remove the /gitlab
. 只需删除
/gitlab
。
nginx configuration file: 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) configuration file: Reference gitlab.conf for gitlab 6.0.6 and gitlab-8.0-apache2.2.conf for gitlab 8.0.0 on apache 2.2 的Apache(2.2.9)的配置文件:参考gitlab.conf为gitlab 6.0.6和gitlab-8.0-apache2.2.conf在Apache 2.2 gitlab 8.0.0
# Module dependencies
# mod_rewrite
# mod_proxy
# mod_proxy_http
<VirtualHost *:80>
ServerAdmin admin@example.com
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>
Have you resolved this issue yet? 你有没有解决这个问题?
If not, try updating the location /
directive to: 如果没有,请尝试将
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;
}
If that doesn't work, please paste the last few lines of /var/log/nginx/gitlab_error.log
. 如果这不起作用,请粘贴
/var/log/nginx/gitlab_error.log
的最后几行。
This configuration works 这种配置有效
# 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;
}
}
And I had a bad symbolic link between nginx available configuration and the enabled configuration. 我在nginx可用配置和启用的配置之间有一个错误的符号链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.