如何更改nginx网站网址

时间:2013-11-16 20:36:04

标签: nginx gitlab

我的ngix站点配置文件(/ etc / nginx / sites-enabled /)如下所示。现在我可以访问localhost来访问此网站,但我想知道如何将网站网址更改为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;
  }
}

3 个答案:

答案 0 :(得分:5)

更新:GitLab现在可以更好地支持相关网址和专用文档:


您想将GitLab移动到相对网址中。请记住,除了nginx配置,您还必须在其他3个地方更改网址。请参阅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下。

答案 1 :(得分:1)

我不知道OP的这些答案是否成功,但对我来说根本没有任何效果:

  • 使用location ...
  • 进行广告投放管理
  • 取消注释具有相对URL等的文件

我找到了一个既优雅又简洁的“调整”,但要求您拥有一个注册域名(不适合本地IP 192.168.0.x):

  1. 设置指向服务器IP的DNS A区域(与您的主域名相同):
    gitlab.mydomain.me
  2. server_name mydomain.me更新为server_name gitlab.mydomain.me;中的/etc/nginx/sites-available/gitlab
  3. 重新启动nginx:sudo service nginx restart
  4. 您现在拥有一个有效的gitlab子域,而您的“主”域名是免费的。

答案 2 :(得分:0)

那么你实际上并没有更改网站名称,而是将其移动到子目录中,这样就可以轻松更改

location / { ... }

是一个子目录

location /gitlab { ... } 

并重新加载nginx然后它应该工作,但你需要确保如果网站没有创建相对URL,那么你需要更改它的配置,所以它不会创建一个链接,将你移到{{{ 1}}目录。