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.
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 iswww-data
.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'
toexternal_url 'http://gitlab.yourdomain.com'
.2.3. Uncomment and change the line
nginx['enable'] = true
tonginx['enable'] = false
.2.4. Uncomment and change the line
web_server['external_users'] = []
toweb_server['external_users'] = ['www-data']
.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;
tolisten 0.0.0.0:7001;
// gitlab runs on port 70013.5. Change this line
listen [::]:80 default_server;
tolisten [::]:7001;
// gitlab runs on port 70013.6. Change this line
server_name YOURSERVER_FQDN
toserver_name www.yourdomain.com
.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;
}
}
}
Reconfigure gitlab and reload nginx
5.1.
sudo gitlab-ctl reconfigure
5.2.
sudo systemctl reload nginx
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
Gui Svn Client for Debian Linux
Libv4L2: Error Turning on Stream: No Space Left on Device
Elastic Beanstalk: Log Task Customization on Amazon Linux 2 Platforms
Gdb/Ddd Program Received Signal Sigill
How to Determine The Available Physical Memory in Linux
Why Does The Linker Modify a -Defsym "Absolute Address"
Bash: Getting Percentage from a Frequency Table
Rtnetlink Answers: No Such File or Directory
How to Remove Warning: Link.Res Contains Output Sections; Did You Forget -T
Cannot Run 32-Bit Apps on 64-Bit Linux
Linux Script with Netcat Stops Working After X Hours
Why Doesn't Time() from Time.H Have a Syscall to Sys_Time
Windows Command Line Equivalent to "Time" in Linux
Reading from a File in Assembly