Jira镜像容器化后nginx反向代理的配置

问题描述:

如果docker容器化jira,使用官方的镜像cptactionhank/atlassian-jira-software:latest,通常会配置域名(ex:jira.test.com)进行访问,如使用nginx进行反向代理。会出现以下错误:

com.atlassian.gadgets.dashboard.internal.diagnostics.UrlHostnameMismatchException: Detected URL hostname, '192.168.10.165', does not match expected hostname, 'jira.proxy.com'
We’ve detected a potential problem with JIRA’s Dashboard configuration that your administrator can correct. Hide Dashboard Diagnostics: Mismatched URL Scheme JIRA is reporting that it is using the URL scheme ‘http’, which does not match the scheme used to run these diagnostics, ‘https’. This is known to cause JIRA to construct URLs using an incorrect hostname, which will result in errors in the dashboard, among other issues. The most common cause of this is the use of a reverse-proxy HTTP(S) server (often Apache or IIS) in front of the application server running JIRA. While this configuration is supported, some additional setup might be necessary in order to ensure that JIRA detects the correct scheme. The following articles describe the issue and the steps you should take to ensure that your web server and app server are configured correctly: Gadgets do not display correctly after upgrade to JIRA 4.0 Integrating JIRA with Apache Integrating JIRA with Apache using SSL If you believe this diagnosis is in error, or you have any other questions, please contact Atlassian Support.

官方以及网上资料均是要求,修改配置文件<JIRA-INSTALL>/conf/server.xml,那么容器下是

/opt/atlassian/jira/conf/server.xml,按照说明操作时没有问题,但jira的容器镜像除外,处理起来比较特殊,下面就介绍配置的坑。

1、修改配置要谨慎

注意标红的地方,jira的容器镜像配置了3个8080端口,其中第一个是在用的,二三都被注释掉了,如果在linux下,稍不注意就会修改第二三个的proxyName和proxyPort,这两个被备注掉了,永远不会生效,还是提示错误。

Jira镜像容器化后nginx反向代理的配置插图

困扰了一下午的时间去排错,最终通过修改端口号才发现原因,希望各位少走弯路,因此把第一个端口配置注释掉,第二个端口配置生效即可,改完配置如下:

Jira镜像容器化后nginx反向代理的配置插图1

代码如下:

 <Connector port="8080" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^&#x5c;&#x60;&quot;&lt;&gt;" maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false" maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true" redirectPort="8443" acceptCount="100" disableUploadTimeout="true" bindOnInit="false" scheme="http" proxyName="jira.test.com" proxyPort="80"/>

一定要让配置生效,jira的容器/opt/atlassian/jira/stop-jira.sh和/opt/atlassian/jira/start-jira.sh不会让tomcat重启,因此要重启容器。

  1. 问题解决,非最优

因为server.xml所在目录非挂载目录,如果删掉容器,配置也就消失了,修改的配置没有保存下来,显然在k8s等平台使用是有问题的,难不成要去修改镜像文件?

其实问题很简单,关键在几个参数,检查容器根目录下的docker-entrypoint.sh文件

if [ "$(stat -c "%Y" "${JIRA_INSTALL}/conf/server.xml")" -eq "0" ]; then if [ -n "${X_PROXY_NAME}" ]; then xmlstarlet ed --inplace --pf --ps --insert '//Connector[@port="8080"]' --type "attr" --name "proxyName" --value "${X_PROXY_NAME}" "${JIRA_INSTALL}/conf/server.xml" fi if [ -n "${X_PROXY_PORT}" ]; then xmlstarlet ed --inplace --pf --ps --insert '//Connector[@port="8080"]' --type "attr" --name "proxyPort" --value "${X_PROXY_PORT}" "${JIRA_INSTALL}/conf/server.xml" fi if [ -n "${X_PROXY_SCHEME}" ]; then xmlstarlet ed --inplace --pf --ps --insert '//Connector[@port="8080"]' --type "attr" --name "scheme" --value "${X_PROXY_SCHEME}" "${JIRA_INSTALL}/conf/server.xml" fi if [ -n "${X_PATH}" ]; then xmlstarlet ed --inplace --pf --ps --update '//Context/@path' --value "${X_PATH}" "${JIRA_INSTALL}/conf/server.xml" fi fi exec "$@"

脚本大致流程如下,检查server.xml最后的修改时间是不是等于0,如果等于零说明没有修改过,那么判断X_PROXY_NAME、X_PROXY_PORT、X_PROXY_SCHEME、X_PATH这4个参数,如果有值则去修改server.xml的配置,也就是说在容器启动之前,配置好环境变量,就可达到我们的目的,其中X_PATH是更新,其他参数是增加。最终jira容器配置如下:

docker run -d \ --name jira-crack-new \ --hostname jira \ -p 20012:8080 \ -e X_PROXY_NAME=test.sd.cmcc \ -e X_PROXY_PORT=80 \ -e X_PROXY_SCHEME=http \ -e X_PATH=/ \ jira:7.12.3

遗留问题,k8s中如果使用2个jira副本,jira会运行冲突,页面出现大量500等错误,多pod的场景还是有问题的,如何实现多pod的高可用还没有解决。

另外提醒mysql5.6以上,默认的连接3306都是https,但jira容器的dbconfig是使用http会出现错误,简单解决就是用mysql5.6的镜像。

文末彩蛋keygen,jira和confluence最新版可用:https://download.csdn.net/download/blue_tear/10764061

原文链接:https://blog.csdn.net/Blue_Tear/article/details/83662418

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享