微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Jenkins 与 nginx 一起使用 docker 端口 50000 配置

如何解决Jenkins 与 nginx 一起使用 docker 端口 50000 配置

我在 Docker 中同时使用 Jenkins 和 Nginx

从 Jenkins docker 文档来看,似乎 jenkins 需要 2 个端口,50000 和 8080,参考:https://github.com/jenkinsci/docker/blob/master/README.md

Nginx 作为反向代理现在有这个配置

server {
    listen 80;
    server_name jenkins.kryptohive.com
    www.jenkins.kryptohive.com;

    server_tokens off;
 
    location /.well-kNown/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://jenkins.kryptohive.com$request_uri;
    }
}

server {
    listen 443 ssl http2;
    server_name www.jenkins.kryptohive.com;
    server_tokens off;
    include /etc/Nginx/conf.d/ssl.kryptohive;    
    return 301 https://jenkins.kryptohive.com$request_uri;   
}

# configuration of the server
server {

    listen      443 ssl http2;
    server_name jenkins.kryptohive.com;

    access_log /var/log/Nginx/jenkins_access.log;
    error_log  /var/log/Nginx/jenkins_error.log;


    include /etc/Nginx/conf.d/ssl.kryptohive;
    include /etc/Nginx/conf.d/gzip_conf;
   
    server_tokens off;



    location / {
      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;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://jenkins:8080;
      proxy_read_timeout  90;

      proxy_redirect      http://jenkins:8080 https://jenkins.kryptohive.com;


      # required for new HTTP-based CLI


      proxy_http_version 1.1;
      proxy_request_buffering off;
      proxy_buffering off;
      add_header 'X-SSH-Endpoint' 'jenkins.kryptohive.com:50000' always;
    }
}

Nginx 配置参考:http://web.archive.org/web/20190723112236/https://wiki.jenkins.io/display/JENKINS/Jenkins+behind+an+NGinX+reverse+proxy

这非常适合为 Jenkins 网站提供服务,但我收到错误

SSL_connect returned=1 errno=0 state=error: certificate verify Failed (unable to get local issuer certificate)

Request headers:
Content-Type: application/json
User-Agent: GitLab/14.0.0-pre
X-Gitlab-Event: Push Hook
Request body:
{
  "object_kind": "push","event_name": "push","before": "e7f7c62995e68446fb1c519fb7f2316eb083bb83","after": "9d62e92972ed32ca67c09108395ebad9a20f3e92","ref": "refs/heads/master","checkout_sha": "9d62e92972ed32ca67c09108395ebad9a20f3e92","message": null,"user_id": 4642285,"user_name": "Abstract Aesthetics","user_username": "4bstractanimation","user_email": "","user_avatar": "https://secure.gravatar.com/avatar/99a9286c8eaf9b7335f91c3ddbdad7fd?s=80&d=identicon","project_id": 26279073,"project": {
    "id": 26279073,"name": "ucurs-default-shop","description": "","web_url": "https://gitlab.com/4bstractanimation/django-standard-shop","avatar_url": null,"git_ssh_url": "git@gitlab.com:4bstractanimation/django-standard-shop.git","git_http_url": "https://gitlab.com/4bstractanimation/django-standard-shop.git","namespace": "Abstract Aesthetics","visibility_level": 0,"path_with_namespace": "4bstractanimation/django-standard-shop","default_branch": "master","ci_config_path": "","homepage": "https://gitlab.com/4bstractanimation/django-standard-shop","url": "git@gitlab.com:4bstractanimation/django-standard-shop.git","ssh_url": "git@gitlab.com:4bstractanimation/django-standard-shop.git","http_url": "https://gitlab.com/4bstractanimation/django-standard-shop.git"
  },"commits": [
    {
      "id": "9d62e92972ed32ca67c09108395ebad9a20f3e92","message": "theme updated\n","title": "theme updated","timestamp": "2021-05-31T20:45:11+05:00","url": "https://gitlab.com/4bstractanimation/django-standard-shop/-/commit/9d62e92972ed32ca67c09108395ebad9a20f3e92","author": {
        "name": "Abstract Aesthetics","email": "4bstractanimation@gmail.com"
      },"added": [

      ],"modified": [
        "public/index.html"
      ],"removed": [

      ]
    },{
      "id": "6eaf6296ce2a7215431ae2e641fd64159fd26be0","timestamp": "2021-05-31T20:44:57+05:00","url": "https://gitlab.com/4bstractanimation/django-standard-shop/-/commit/6eaf6296ce2a7215431ae2e641fd64159fd26be0","added": [
        "src/components/admin-view/images/logo_feild.js"
      ],"modified": [
        "src/StateStore/reducer.js","src/components/admin-view/images/index.js","src/components/admin-view/information/TextView.js","src/components/admin-view/information/index.js","src/components/layout/footer/index.js","src/components/layout/header/index.js"
      ],{
      "id": "e7f7c62995e68446fb1c519fb7f2316eb083bb83","timestamp": "2021-05-31T19:38:49+05:00","url": "https://gitlab.com/4bstractanimation/django-standard-shop/-/commit/e7f7c62995e68446fb1c519fb7f2316eb083bb83","added": [
        "src/components/customers-view/filter-product/price_filter.js"
      ],"modified": [
        "public/index.html","src/components/customers-view/filter-product/index.js","src/components/customers-view/populated-view/index.js","src/components/customers-view/single-product-card/index.js","src/components/customers-view/single-product-view/index.js"
      ],"removed": [

      ]
    }
  ],"total_commits_count": 3,"push_options": {
  },"repository": {
    "name": "ucurs-default-shop","visibility_level": 0
  }
}

当我尝试将 GitLab 连接到 jenkins 时。

我如何配置 Nginx 以通过 ssl 服务 jenkins 的 50000 端口 我的 docker compose 环境:

version: "3.4"

services:

# JENKINS

  jenkins:
    image: jenkins/jenkins:lts-jdk11
    volumes:
      - ${PWD}/Jenkins:/var/jenkins_home   


# Nginx SERVER
  Nginx_server:
    image: webdevops/PHP-Nginx:7.3
    volumes:
      - ${PWD}/config/Nginx/conf.d:/etc/Nginx/conf.d
      - ${PWD}/log/Nginx:/var/log/Nginx
      - ${PWD}/../get-cert/data/certbot/conf:/certs
    ports:
      - 80:80    # app port
      - 443:443
      - 50000:50000
    container_name: Nginx_server
#####################################################

编辑 问题实际上出在 SSL 上,因为我尝试运行

curl jenkins.kryptohive.com

它给出了以下错误

    curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl Failed to verify the legitimacy of the server and therefore Could not
establish a secure connection to it. To learn more about this situation and
how to fix it,please visit the web page mentioned above.

我重新创建了 SSL 证书,但仍然出现相同的错误,尽管在浏览器中它似乎验证了我的 ssl 证书

解决方法

这可能是一些缓存问题,因为当我在 nginx 中为代理标头注释一些代码时它起作用了。 并重新启动服务器 之后我再次取消注释该代码并重新启动服务器,它仍然有效。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。