how to change nginx site url
Solution 1
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
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"
All these configs are under /home/git/gitlab/config
.
Solution 2
I don't know if these answers have been successful for OP, but for me nothing worked at all :
- trafficking with
location
... - Uncommenting files with relative URL, etc .
I did find a "tweak" which both elegant and concise, but requires you to have a registered domain name (not suitable for local IPs 192.168.0.x
) :
- Set up a DNS A Zone pointing to your server's IP (the same as your main domain) :
gitlab.mydomain.me
. - Update
server_name mydomain.me
toserver_name gitlab.mydomain.me;
in/etc/nginx/sites-available/gitlab
. - Restart nginx :
sudo service nginx restart
.
You now have a working gitlab subdomain, and your "main" domain is free.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on June 04, 2022Comments
-
Admin about 2 years
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 tolocalhost/gitlab
. I needlocalhost
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; } }