How to Configure Gitlab as a Subdomain in Nginix.Conf

Forwarding to GitLab Subdomain with Existing Nginx Installation

Based on @cyberchis's answer i simplified the process, and I have got through the same setup twice. I hope that it also works for you.

  1. Check the user of nginx

    1.1. Open nginx.conf with nano /etc/nginx/nginx.conf.

    1.2. Check the 1st. line user www-data;, and the user here is www-data.

  2. Edit external_url of gitlab

    2.1. Open gitlab.rb with nano /etc/gitlab/gitlab.rb.

    2.2. Edit the line external_url 'GENERATED_EXTERNAL_URL' to external_url 'http://gitlab.yourdomain.com'.

    2.3. Uncomment and change the line nginx['enable'] = true to nginx['enable'] = false.

    2.4. Uncomment and change the line web_server['external_users'] = [] to web_server['external_users'] = ['www-data'].

  3. Add a configuration file for gitlab

    3.1. Download the gitlab-omnibus-nginx.conf from gitlab repository.

    3.2. Go to the directory where the file is, and copy this file to nginx with cp /directory-to-this-file/gitlab-omnibus-nginx.conf /etc/nginx/sites-enabled.

    3.3. Open this file with nano /etc/nginx/sites-enabled/gitlab-omnibus-nginx.conf.

    3.4. Change this line listen 0.0.0.0:80 default_server; to listen 0.0.0.0:7001; // gitlab runs on port 7001

    3.5. Change this line listen [::]:80 default_server; to listen [::]:7001; // gitlab runs on port 7001

    3.6. Change this line server_name YOURSERVER_FQDN to server_name www.yourdomain.com.

  4. Configure nginx

    4.1. Open nginx.conf with nano /etc/nginx/nginx.conf.

    4.2. Add this configuration

http {

...

server {
listen 80;
server_name gitlab.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:7001;
}
}
}

  1. Reconfigure gitlab and reload nginx

    5.1. sudo gitlab-ctl reconfigure

    5.2. sudo systemctl reload nginx

  2. Configure firewall to export port 7001 (Optional)

    Since the gitlab runs on my local server, therefore the port 7001 has to been allowed to reach from the outside. Easiest way to enable it is to run ufw allow 7001.

Now the gitlab runs on your subdomain gitlab.yourdomain.com which you should access.

How to configure GitLab as a subdomain in nginix.conf

Here is my setup that works on a subdomain.

server {
listen 80;
server_name gitlab.example.com;
root /home/gitlab/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_redirect off;
# you need to change this to "https", if you set "ssl" directive to "on"
proxy_set_header X-FORWARDED_PROTO http;
proxy_set_header Host gitlab.example.com:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}

subdomains + nginx + reverse proxy + jenkins + gitlab

Well you have a few different questions. First DNS related questions. If you have domain.tld then you go to whomever manages the DNS for that domain and add a CNAME or A record which points to your nginx server.

As for your Jenkins nginx setup. I would create a new file like jenkins.domain.tld.conf and put in this which I copied from here

server {

listen 80;
server_name jenkins.domain.tld;

location / {

proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# Fix the "It appears that your reverse proxy set up is broken" error.
proxy_pass http://127.0.0.1:8080;
proxy_read_timeout 90;

proxy_redirect http://127.0.0.1:8080 https://jenkins.domain.tld;

# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
# workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
add_header 'X-SSH-Endpoint' 'jenkins.domain.tld:50022' always;
}
}

For each sub domain go to Google and search for service nginx and you should find advice on how do set it up.

How to setup nginx and a subdomain

The problem was this line of code: listen *:80;

to solve the problem I must use this: listen 80;

Auto deploy rails Gitlab projects to subdomains with Nginx and Phusion Passenger

GitLab uses on Gitolite.

And Gitolite allows for update hook as VREF: you can declare one applied for all repos which would generate the file you want and make the appropriate actions, only if said repo is empty (just been created).



Related Topics



Leave a reply



Submit