简体   繁体   English

docker-compose gitlab 与 Nginx 但 ssh 失败

[英]docker-compose gitlab with Nginx but ssh failed

I am use docker-compose for building Nginx and gitlab on the same server which is on GCP.我使用 docker-compose 在 GCP 上的同一台服务器上构建 Nginx 和 gitlab。 And I am using Cloudflare to manage my DNS, I have a domain name gitlab.mydomain.com which is binding with my GCP static IP (for example my ip is 123.45.67.89 ). And I am using Cloudflare to manage my DNS, I have a domain name gitlab.mydomain.com which is binding with my GCP static IP (for example my ip is 123.45.67.89 ).

So I want to use this domain to access my gitlab with Nginx, the following is my docker-compose.yml file:所以我想用这个域来访问我的gitlab和Nginx,下面是我的docker-compose.yml文件:

version: '3.5'

services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    restart: always
    hostname: 'gitlab.mydomain.com'
    privileged: true
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.mydomain.com:7788'
        gitlab_rails['gitlab_shell_ssh_port'] = 9453
    ports:
      - '7788:80'
      - '9453:22'
    volumes:
      - /gitlab/data:/var/opt/gitlab
      - /gitlab/logs:/var/log/gitlab
      - /gitlab/config:/etc/gitlab
    networks:
      - net-proxy
  nginx:
    image: nginx
    container_name: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "80:80"
networks:
   net-porxy:
      external:
         name: my-network

And this is my Nginx.conf file:这是我的Nginx.conf文件:

server {
    listen 80;
    server_name gitlab.mydomain.com;
    proxy_connect_timeout       300;
    proxy_send_timeout          300;
    proxy_read_timeout          300;
    send_timeout                300;
    location ~ / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://123.45.67.89:7788;
    }
}

I also add this line in my gitlab.rb file我还在我的gitlab.rb文件中添加了这一行

external_url 'http://gitlab.mydomain.com'

I changed my ssh port from 22 to 9453 port, and I can access my gitlab service by my domain gitlab.mydomain.com , and I can also clone my git repo with http, but when I want to clone with ssh I changed my ssh port from 22 to 9453 port, and I can access my gitlab service by my domain gitlab.mydomain.com , and I can also clone my git repo with http, but when I want to clone with ssh

git clone ssh://git@gitlab.mydomain.com:9453/myproject/myrepo.git , it will always show operation time out. git clone ssh://git@gitlab.mydomain.com:9453/myproject/myrepo.git , it will always show operation time out.

But if I replace my ssh domain with ip:但是,如果我用 ip 替换我的 ssh 域:

git clone ssh://git@123.45.67.89:9453/myproject/myrepo.git

It's worked!!!成功了!!!

I'm not sure if this is because my domain was reverse proxy by Nginx.我不确定这是否是因为我的域是 Nginx 的反向代理。 If I want to clone my repo by domain with Nginx, how can I do, please.如果我想用 Nginx 按域克隆我的仓库,请问我该怎么做。

As mentioned here , NGiNX does not do SSH forwarding, only HTTP.这里提到,NGiNX不做SSH转发,只做HTTP。

So:所以:

For example: Port forwarding over SSH例如: SSH上的端口转发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM