如何更改Nginx网站网址 [英] how to change nginx site url

查看:124
本文介绍了如何更改Nginx网站网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ngix网站配置文件(/etc/nginx/sites-enabled/)在下面给出.现在,我可以通过转到localhost来访问此站点,但是我想知道如何将站点URL更改为localhost/gitlab.我需要localhost保留用于其他网站.

My ngix site config file (/etc/nginx/sites-enabled/) is given below. Right now I can access this site by going to localhost but I would like to know how to change the site url to localhost/gitlab. I need localhost reserved for a different website.

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

推荐答案

更新:GitLab现在对相对URL和专用文档提供了更好的支持:

Update: GitLab now has better support for relative URLs and dedicated documentation:

  • Source installations http://docs.gitlab.com/ee/install/relative_url.html
  • Omnibus packages https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-a-relative-url-for-gitlab

您想在相对URL中移动GitLab.请记住,除了nginx配置外,还必须在其他3个地方更改url.请参阅gitlab.yml中的说明:

You want to move GitLab in a relative url. Bear in mind that except for the nginx config, you must also change the url in 3 other places. See the directions in 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下.

这篇关于如何更改Nginx网站网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆