【问题标题】:how to change nginx site url如何更改 nginx 站点 url
【发布时间】:2013-11-30 04:10:30
【问题描述】:

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

【问题讨论】:

    标签: nginx gitlab


    【解决方案1】:

    您实际上并没有更改站点名称,而是将其移动到子目录,因此您可以轻松更改

    location / { ... }
    

    作为子目录

    location /gitlab { ... } 
    

    然后重新加载 nginx,它应该可以工作,但是你需要确保如果网站没有创建相对 URL,那么你需要更改它的配置,这样它就不会创建一个链接,将你移到 @987654323 之外@目录。

    【讨论】:

      【解决方案2】:

      更新: 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下。

      【讨论】:

      • 优秀。谢谢。
      【解决方案3】:

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

      • location 进行交易...
      • 使用相对 URL 等取消注释文件。

      我确实找到了一个既优雅又简洁的“tweak”,但要求你有一个注册的域名(不适合本地IP192.168.0.x):

      1. 设置一个指向您的服务器 IP(与您的主域相同)的 DNS A 区域:
        gitlab.mydomain.me
      2. /etc/nginx/sites-available/gitlab 中将server_name mydomain.me 更新为server_name gitlab.mydomain.me;
      3. 重启nginx:sudo service nginx restart

      你现在有一个工作的 gitlab 子域,你的“主”域是免费的。

      【讨论】:

        猜你喜欢
        • 2010-11-01
        • 2016-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多