我正在尝试在一台服务器上配置 Nginx,通过反向代理路由到另一台服务器 (192.168.1.3) 上的默认 GitLab 安装,以便 GitLab 可以在路径上工作http://我的服务器/gitlab,https://我的服务器/gitlab,http://192.168.1.3, 和https://192.168.1.3。但是,我认为我遇到了麻烦,因为 GitLab 所在的服务器也使用 Nginx 作为自己的反向代理。因此,我不确定如何在两台服务器上配置 Nginx 以使 GitLab 正常工作。
以下是主 Nginx 服务器上当前 Nginx 的配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name myserver;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass $scheme://192.168.1.4;
}
location ~/gitlab/(.*)$ {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass $scheme://192.168.1.3/$1;
}
}
以下是 GitLab 服务器上默认的 Nginx 配置:
upstream gitlab {
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0;
}
upstream gitlab-workhorse {
server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;
}
server {
listen 0.0.0.0:80;
include /etc/nginx/include/gitlab-proxy;
}
server {
listen 0.0.0.0:443 ssl;
include /etc/nginx/include/ssl;
include /etc/nginx/include/gitlab-proxy;
}
/etc/nginx/include/gitlab-proxy 上的内容如下:
root /home/git/gitlab/public;
access_log /var/log/nginx/gitlab.access.log;
error_log /var/log/nginx/gitlab.error.log;
location / {
try_files $uri $uri/index.html $uri.html @gitlab;
}
location @gitlab {
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-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://gitlab;
proxy_redirect off;
proxy_buffering off;
}
location ~ [-\/\w\.]+\.git\/ {
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-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://gitlab-workhorse;
proxy_redirect off;
proxy_buffering off;
proxy_connect_timeout 300;
proxy_read_timeout 300;
}
gitlab的主机名在GitLab服务器上寻址到127.0.0.1。
仅供参考,这个问题与问题类似这里除了它特别要求 SSL。GitLab 环境 GITLAB_RELATIVE_URL_ROOT 已更改。我不知道如何更改它,甚至不想更改它,因为我希望它仍然可以通过以下方式访问http://192.168.1.3和https://192.168.1.3。此外,它还为 Nginx 使用 Docker 容器。