参考资料

  1. FastCGI(Fast Common Gateway Interface,快速通用网关接口)详细说明以及案例
  2. Nginx访问日志配置详细说明以及案例
  3. Nginx静态资源服务器搭建详细说明以及案例
  4. Nginx + PHP-FPM 配置指南
  5. nginx 配置https
  6. Nginx的配置与管理
  7. nginx代理详细讲解
  8. 如何使用Nginx模块增强安全性?

Nginx 配置 GitLab 归档工具

1. 安装 Nginx

确保已安装 Nginx,若未安装,使用以下命令:

sudo apt-get update
sudo apt-get install nginx

2. 配置 Nginx

编辑 Nginx 配置文件 /etc/nginx/nginx.conf/etc/nginx/sites-available/default,添加以下内容:

server {
    listen 80;
    server_name gitlab.example.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        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;
    }

    location /archive/ {
        alias /var/opt/gitlab/gitlab-rails/shared/artifacts/;
        autoindex on;
    }
}

3. 配置 GitLab

编辑 GitLab 配置文件 /etc/gitlab/gitlab.rb,确保以下设置:

external_url 'http://gitlab.example.com'
nginx['enable'] = false

4. 重启服务

保存配置后,重启 Nginx 和 GitLab:

sudo systemctl restart nginx
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

5. 访问归档文件

通过 http://gitlab.example.com/archive/ 访问归档文件。

案例

假设 GitLab 运行在 http://127.0.0.1:8080,归档文件存储在 /var/opt/gitlab/gitlab-rails/shared/artifacts/,配置如下:

server {
    listen 80;
    server_name gitlab.example.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        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;
    }

    location /archive/ {
        alias /var/opt/gitlab/gitlab-rails/shared/artifacts/;
        autoindex on;
    }
}

配置完成后,访问 http://gitlab.example.com/archive/ 即可查看归档文件。