使GitLab在Nginx反向代理后面运行

时间:2019-08-01 21:07:38

标签: docker nginx docker-compose gitlab reverse-proxy

我试图让gitlab在Nginx反向代理后面工作,但是失败了。两者都通过docker-compose在docker容器中运行。

Docker版本18.09.7,内部版本2d0083d

docker-compose版本1.17.1,版本未知

docker-compose文件的某些部分。

services:
 nginx:
  image: 'nginx:latest'
  container_name: 'nginx'
  networks:
   docker_edu_net:
    ipv4_address: 172.111.1.2 
  restart: always
  hostname: 'nginx'
  privileged: true
  user: root
  ports:
   - 80:80
   - 443:443
  volumes:
   - /opt/nginx/nginx.conf:/etc/nginx/nginx.conf
   - /opt/nginx/conf.d:/etc/nginx/conf.d
   - /var/log/nginx:/var/log/nginx
   - /opt/www:/opt/www 

 gitlab:
  image: 'gitlab/gitlab-ce:latest'
  container_name: 'gitlab'
  networks:
   docker_edu_net:
    ipv4_address: 172.111.1.3
  ports:
   - '10080:80'
  restart: always
  hostname: 'gitlab'
  privileged: true
  user: root
  environment:
   GITLAB_OMNIBUS_CONFIG: |
    external_url 'http://gitlab.edu.org'
  volumes:
   - '/home/user/data/docker/gitlab/config:/etc/gitlab' 
   - '/home/user/data/docker/gitlab/logs:/var/log/gitlab'
   - '/home/user/data/docker/gitlab/data:/var/opt/gitlab'

nginx配置文件:

    events {
            worker_connections 128;
    }

    http{
            server {
                    listen 80;
                    server_tokens off;
                    server_name gitlab.edu.org;

                    access_log /var/log/nginx/reverse-access.log;
                    error_log /var/log/nginx/reverse-error.log debug;

                    location /gitlab/ {
                            proxy_pass http://192.168.241.135:10080/;
                            rewrite ^/gitlab/$ http://$server_name/gitlab/users/sign_in permanent;
                            proxy_http_version 1.1;
                            #proxy_redirect off;
                            proxy_redirect http://192.168.241.135:10080/ http://$server_name/gitlab/;
                            proxy_set_header Host $host;
                            proxy_set_header X-Real-IP $remote_addr;
                    }
       }
}

我收到404错误:

 21:04:43 [error] 6#6: *1 open() "/etc/nginx/html/gitab" failed (2: No such file or directory), client: 172.111.1.1, server: gitlab.edu.org, request: "GET /gitab HTTP/1.1", host: "gitlab.edu.org"

我该如何工作?

谢谢

1 个答案:

答案 0 :(得分:1)

不确定您是否注意到了此消息,但您的GET请求似乎有错字-是/gitab,而不是/gitlab ...