如何更改nginx站点url
我的ngix站点配置文件(/etc/nginx/sites enabled/)如下所示。现在我可以通过转到如何更改nginx站点url,nginx,gitlab,Nginx,Gitlab,我的ngix站点配置文件(/etc/nginx/sites enabled/)如下所示。现在我可以通过转到localhost访问此站点,但我想知道如何将站点url更改为localhost/gitlab。我需要为不同的网站保留localhost upstream gitlab { server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; } server { # listen *:80 default_server; #
localhost
访问此站点,但我想知道如何将站点url更改为localhost/gitlab
。我需要为不同的网站保留localhost
upstream gitlab {
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}
server {
# listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
server_name localhost; # e.g., server_name source.example.com;
server_tokens off; # don't show the version number, a security best practice
root /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;
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;
}
}
实际上,您并没有更改站点名称,而是将其移动到一个子目录,这样您就可以轻松地更改
location / { ... }
作为子目录
location /gitlab { ... }
然后重新加载nginx,它应该可以工作了,但您需要确保,如果网站没有创建相对URL,那么您需要更改其配置,这样它就不会创建将您移出
/gitlab
目录的链接。更新:gitlab现在对相对URL和专用文档有了更好的支持:
- 源安装
- 综合包
您希望在相对url中移动GitLab。请记住,除了nginx配置之外,您还必须在其他3个位置更改url。请参见gitlab.yml中的说明:
# Uncomment and customize the last line to run in a non-root path
# WARNING: This feature is known to work, but unsupported
# 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'] = "/gitlab"
所有这些配置都在
/home/git/gitlab/config
下,我不知道这些答案对于OP是否成功,但对我来说,没有任何效果:
- 利用
地点进行贩运
- 使用相对URL等取消对文件的注释
192.168.0.x
):
gitlab.mydomain.me
server\u name mydomain.me
更新为server\u name gitlab.mydomain.me代码>在/etc/nginx/sites available/gitlab
中
sudo服务nginx重新启动
您现在有了一个工作的gitlab子域,您的“主”域是免费的。非常好。非常感谢。