使用现有 Nginx 安装转发到 GitLab 子域 [英] Forwarding to GitLab Subdomain with Existing Nginx Installation

查看:92
本文介绍了使用现有 Nginx 安装转发到 GitLab 子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注 来自 GitLab wiki 的说明,但是,似乎缺少一些关键信息.在使用非捆绑的 Web 服务器"部分中,它从未解释我需要如何重新配置​​我的 Nginx 安装以将代理反向代理到 GitLab.

I've been following the instructions from the GitLab wiki, however, it seems as if some key pieces of information are missing. In the section "Using a Non-Bundled Web Server" it never explains how I need to reconfigure my Nginx installation to reverse proxy over to GitLab.

基本上,我希望将 GitLab 安装在 git.example.com 下,但我似乎无法为我现有的 Nginx 安装找到可以执行此操作的配置设置.wiki 页面继续讨论配置现有的Passenger/Nginx 安装,但我没有Passenger,所以我认为这不适用于我的情况.

Basically, I'd like to have GitLab installed under git.example.com, but I can't seem to find the configuration settings for my existing Nginx installation that'll do that. The wiki page goes on to talk about configuring an existing Passenger/Nginx installation, but I don't have Passenger, so I don't think that applies to my situation.

我想最简单的解决方案是,如果有办法告诉 Gitlab 使用它的内置 Nginx 并只监听内部端口,然后让我的其他 Nginx 转发到该端口,但我似乎无法弄清楚如何配置 Gitlab 来处理这个问题.

I suppose the easiest solution would be if there were a way to tell Gitlab to use it's built-in Nginx and just listen on an internal port, and then have my other Nginx forward to that port, but I can't seem to figure out how to configure Gitlab to handle that.

任何帮助将不胜感激.

推荐答案

根据@cyberchis 的回答,我简化了流程,我已经完成了两次相同的设置.我希望它也对你有用.

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. 查看nginx的用户

1.1.使用 nano/etc/nginx/nginx.conf 打开 nginx.conf.

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

1.2.检查第 1 个.line user www-data;,这里的用户是www-data.

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

编辑gitlab的external_url

2.1.使用 nano/etc/gitlab/gitlab.rb 打开 gitlab.rb.

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

2.2.将 external_url 'GENERATED_EXTERNAL_URL' 行编辑为 external_url 'http://gitlab.yourdomain.com'.

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

2.3.取消注释并将 nginx['enable'] = true 行更改为 nginx['enable'] = false.

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

2.4.取消注释并将 web_server['external_users'] = [] 行更改为 web_server['external_users'] = ['www-data'].

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

为 gitlab 添加配置文件

3.1.从 gitlab-omnibus-nginx.conf"nofollow noreferrer">gitlab 仓库.

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

3.2.转到文件所在的目录,并使用 cp/directory-to-this-file/gitlab-omnibus-nginx.conf/etc/nginx/sites-enabled 将此文件复制到 nginx.

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.使用 nano/etc/nginx/sites-enabled/gitlab-omnibus-nginx.conf 打开这个文件.

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

3.4.将此行 listen 0.0.0.0:80 default_server; 改为 listen 0.0.0.0:7001;//gitlab 运行在 7001 端口

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.将这一行 listen [::]:80 default_server; 改为 listen [::]:7001;//gitlab 运行在 7001 端口

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

3.6.将此行 server_name YOURSERVER_FQDN 更改为 server_name www.yourdomain.com.

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

配置 nginx

4.1.使用 nano/etc/nginx/nginx.conf 打开 nginx.conf.

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

4.2.添加此配置

http {

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

  1. 重新配置gitlab并重新加载nginx

5.1.sudo gitlab-ctl reconfigure

5.2.sudo systemctl reload nginx

将防火墙配置为导出端口 7001(可选)

由于 gitlab 在我的本地服务器上运行,因此必须允许从外部访问端口 7001.启用它的最简单方法是运行 ufw allow 7001.

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.

现在 gitlab 在您应该访问的子域 gitlab.yourdomain.com 上运行.

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

这篇关于使用现有 Nginx 安装转发到 GitLab 子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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