The UTF-8 coding problem of Jenkins

Posted by rfrid on Thu, 02 Apr 2020 22:30:04 +0200

Jenkins is easy to get cramped sometimes. I configured the code in tomcat, which is not easy to use. I started because of the problem of nginx's reverse proxy, but later found out that Tomcat became a demon. The solution is to copy my Tomcat configuration, and then add parameters and modify on my basis.

Error screenshots

1. Configure nginx

After nginx is configured, you need to configure nginx and set https access.

upstream  proxy_pool_jenkins {
        server 192.168.156.45:8080 weight=10;
    keepalive 512;
}

server
    {
        #listen 80;
            listen 443 ssl;
                    ssl_certificate      server.pem;
                    ssl_certificate_key  server.key;

                    ssl_session_cache    shared:SSL:1m;
                    ssl_session_timeout  5m;

                    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                    ssl_ciphers  HIGH:!aNULL:!MD5;
                    ssl_prefer_server_ciphers  on;
            charset utf-8;  
                server_name jenkins.yellowcong.net;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /data/jeeroot/jenkins.yellowcong.net/ROOT;

        #error_page   404   /404.html;
        location / {
                        proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404;
                        proxy_read_timeout 4s;

            proxy_http_version 1.1;
                        proxy_set_header Connection "";
                        proxy_connect_timeout 10;

            proxy_redirect off;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $host;
                    #proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://proxy_pool_jenkins;
            #proxy_redirect http://proxy_pool_jenkins $scheme://jenkins.yellowcong.net;
            }
        location ~ ^/(WEB-INF)/ {
                deny all;
            }

        location /nginx_status {
            stub_status on;
            access_log   off;
        }

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        location = /robots.txt {
            log_not_found off;
            access_log off;
        }

        location ~/\. {
            deny all;
            access_log off;
            log_not_found off;
        }

            location ~ /\.(ht|svn|git) {
                    deny all;
            }

        access_log  /home/wwwlogs/jenkins.yellowcong.net.log  access;
    }
server {
        listen 80;
        server_name jenkins.yellowcong.net;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /data/wwwroot/jira.yellowcong.net/;
        return 301 https://$server_name$request_uri;
}

2. Configure tomcat

Configure the conf/server.xml configuration under the tomcat directory. If you don't copy directly, there may be problems with your coding. It's better to add parameters on my basis

 <Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            URIEncoding="UTF-8"
            redirectPort="8443"
            proxyName="jenkins.yellowcong.net" 
            scheme="https" 
            proxyPort="443" />

After restarting tomcat, that annoying mistake finally disappeared.

Topics: jenkins Tomcat Nginx PHP