Как исправить ошибку 400 Hook должен содержать полезную нагрузку для Jenkins, работающего за сервером Nginx - PullRequest
0 голосов
/ 06 августа 2020

Jenkins работает за сервером Nginx на виртуальной машине CentOS. Я могу получить доступ к Jenkins через веб-интерфейс в веб-браузере. Поскольку я хочу запускать автоматические c сборки, когда код помещается в репозиторий GitHub, я определил веб-хук репозитория Github.

Затем я отредактировал NGINX конфигурационный файл

/etc/nginx/nginx.conf

путем добавления местоположения с помощью:

 location /github-webhook {
   proxy_pass http://localhost:8080/github-webhook;
   proxy_method POST;
   proxy_connect_timeout 150;
   proxy_send_timeout 100;
   proxy_read_timeout 100;
   proxy_buffers 4 32k;
   client_max_body_size 8m;
   client_body_buffer_size 128k;
 }

Но когда Github отправляет запрос POST, Дженкинс отправляет обратно 400 Hook should contain payload ответ. Могу ли я что-нибудь сделать, чтобы решить эту проблему?

Ниже приведен полный файл конфигурации Nginx (имя домена было изменено на xyz.com):

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

upstream jenkins{
   server 127.0.0.1:8080;
   keepalive 16;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name xyz.com;

    ssl_certificate /etc/letsencrypt/live/xyz.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/xyz.com/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
    ssl_session_tickets off;

    # intermediate configuration
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers off;

    # HSTS (ngx_http_headers_module is required) (63072000 seconds)
    add_header Strict-Transport-Security "max-age=63072000" always;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;


    # replace with the IP address of your resolver 
    resolver 127.0.0.1;

    ignore_invalid_headers off;

 location /github-webhook {
   proxy_pass http://localhost:8080/github-webhook;
   proxy_method POST;
   proxy_connect_timeout 150;
   proxy_send_timeout 100;
   proxy_read_timeout 100;
   proxy_buffers 4 32k;
   client_max_body_size 8m;
   client_body_buffer_size 128k;
 }

location / {
        proxy_pass http://jenkins;

        # we want to connect to Jenkins via HTTP 1.1 with keep-alive connections
        proxy_http_version 1.1;

        # has to be copied from server block, 
        # since we are defining per-location headers, and in 
        # this case server headers are ignored
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # no Connection header means keep-alive
        proxy_set_header Connection "";

        # Jenkins will use this header to tell if the connection
        # was made via http or https
        proxy_set_header X-Forwarded-Proto $scheme;

        # increase body size (default is 1mb)
        client_max_body_size       10m;

        # increase buffer size, not sure how this impacts Jenkins, but it is recommended
        # by official guide
        client_body_buffer_size    128k;

        # block below is for HTTP CLI commands in Jenkins

        # increase timeouts for long-running CLI commands (default is 60s)
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;

        # disable buffering
        proxy_buffering            off;
        proxy_request_buffering    off;
    }
}
}

И здесь это настройки веб-перехватчика GitHub:

enter image description here

In Jenkins projects configuration Github was configured as:

введите описание изображения здесь

1 Ответ

0 голосов
/ 06 августа 2020

Проблема была решена путем установки поля Jenkins URL с http://localhost:8080/ вместо xyz.com:8080/. Вы можете получить доступ к этому полю, перейдя в Jenkins> Manage Jenkins> Configure System

введите описание изображения здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...