大网数据广告活动
服务器运维问答

GitLab behind nginx doesn't work

· 52CE 我爱测

My GitLab is running on port 9999 and it can be accessed using the below URL http://server01.example.com:9999/ (which redirects to http://server01.example.com:9999/users/sign_in ) or it can be directly accessed on the below URL h…

问题原文

原帖链接 · Gokulnath Kumar · CC BY-SA 4.0

My GitLab is running on port 9999 and it can be accessed using the below URL

http://server01.example.com:9999/ (which redirects to http://server01.example.com:9999/users/sign_in)

or it can be directly accessed on the below URL http://server01.example.com:9999/users/sign_in

I have configured nginx to listen on port 443. Here is how my current configuration looks like,.

server {
        client_max_body_size 40M;
        listen 443;
        server_name server01.example.com;

        location /gitlab/ {
                rewrite ^/.* http://$server_name/gitlab/users/sign_in permanent;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://127.0.0.1:9999/users/sign_in/;
                proxy_redirect off;
        }
}

When I try to access http://server01.example.com:443/gitlab/

It is getting redirected to the following URL,

http://server01.example.com/gitlab/users/sign_in

and tell me that "page not found error". Nginx error log shows me the following.

2018/07/15 07:09:37 [error] 20300#0: *3 open() "/usr/share/nginx/html/gitlab/users/sign_in" failed (2: No such file or directory), client: xx.xxx.xxx.xxx, server: _, request: "GET /gitlab/users/sign_in HTTP/1.1", host: "server01.example.com"

Update1:

Current Configuration:

server {
        client_max_body_size 40M;
        listen 443 ssl;
        server_name server01.example.com;
        ssl_certificate /etc/nginx/ssl/tlscert.crt;
        ssl_certificate_key /etc/nginx/ssl/private.key;

        location /gitlab/ {
                rewrite ^/.* https://$server_name/gitlab/users/sign_in/ permanent;
                proxy_pass http://127.0.0.1:9999/;
                proxy_redirect http://127.0.0.1:9999/ https://$server_name/gitlab/;
        }
}

https://server01.example.com/gitlab/users/sign_in

This page isn’t working server01.example.com redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS

已采纳解答

原帖链接 · Leo Gallego · CC BY-SA 4.0

It would be useful if you specify your nginx version (gitlab version, linux distribution and version wouldn't hurt either).

I would probably use a few tweaks in your config, disable the redirect and send the headers for the proxy:

server {
        listen 443 ssl;
        server_name server01.example.com;

        client_max_body_size 40M;

        ssl_certificate /etc/nginx/ssl/tlscert.crt;
        ssl_certificate_key /etc/nginx/ssl/private.key;

        location /gitlab/ {
                proxy_pass http://127.0.0.1:9999/;
                proxy_redirect    off;

                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header  Host $http_host;

        }
}

If that doesn't work (it will depend on your nginx version) I would try something with a rewrite, like:

server {
        listen 443 ssl;
        server_name server01.example.com;

        client_max_body_size 40M;

        ssl_certificate /etc/nginx/ssl/tlscert.crt;
        ssl_certificate_key /etc/nginx/ssl/private.key;

        location /gitlab/ {
                rewrite ^/gitlab(/.*)$ $1 break;
                proxy_pass http://127.0.0.1:9999/;
                proxy_redirect    off;

                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header  Host $http_host;

        }
}

But I would leave the redirect off either way. I think that's causing your problems.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。