修改 Sonatype Nexus2 的 baseUrl

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/maosidiaoxian/article/details/82849138

背景:
搭建 nexus 是使用的 sonatype 的官方 nexus docker 镜像,跑起来之后,发现访问路径带了 /nexus 而不是 /,于是想修改这个路径。

尝试方法一:
以管理员账号登录,打开 Administration 中的 Servier 面板,修改 Application Server Settings 里的 Base URL 配置。
但发现无效。勾上 Force Base URL 之后依然不起作用,仓库不加上 /nexus 无法访问。
此处实际上修改的是 nexus 数据目录下的 conf/nexus.xml 配置文件。

尝试方法二:
参考 https://stackoverflow.com/a/29561898/2673757,但发现在 conf 文件夹下没有 nexus.properties,尝试创建此文件并写入上面答案的配置,然而依旧不起作用。

最终解决的方法:
在官方的 docker-nexus 开源项目(https://github.com/sonatype/docker-nexus )中,发现有这样一段话(https://github.com/sonatype/docker-nexus#notes):

Notably: /opt/sonatype/nexus/conf/nexus.properties is the properties file. Parameters (nexus-work and nexus-webapp-context-path) defined here are overridden in the JVM invocation.

其下有关于环境变量的说明:

  • Environment variables can be used to control the JVM arguments
  • CONTEXT_PATH, passed as -Dnexus-webapp-context-path. This is used to define the URL which Nexus is accessed. Defaults to ‘/nexus’

于是修改 docker 启动脚本,增加一个 CONTEXT_PATH 的环境变量,值为空字符串。

#!/bin/bash
sudo docker run -d \
--name nexus \
--restart always \
-p 8081:8081 \
-v /data-storage/nexus:/sonatype-work  \
-e CONTEXT_PATH="" \
sonatype/nexus

停止原来的容器并删除,重新启动新的 docker 容器,成功。

猜你喜欢

转载自blog.csdn.net/maosidiaoxian/article/details/82849138
今日推荐