nexus@配置https支持nexus

在 Nexus Repository Manager 3 中启用 HTTPS(即让 Nexus 服务通过 https:// 安全访问)并不直接由 Nexus 内部控制,而是通过配置反向代理(如 Nginx、Apache)或直接使用 Java 的 Jetty 绑定 SSL 实现。


✅ m1.通过 Nginx 配置 HTTPS(推荐)

🔧 1.申请 SSL 证书

  • Let’s Encrypt 免费证书(推荐)
  • 商业证书(如阿里云、腾讯云、Digicert 等)

证书文件通常包括:

  • fullchain.pem(或 .crt
  • privkey.pem(私钥)

🧱 2.安装并配置 Nginx

假设你已经在服务器上安装了 Nginx:

示例配置(/etc/nginx/conf.d/nexus.conf):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
listen 443 ssl;
server_name nexus.example.com;

ssl_certificate /etc/nginx/ssl/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;

location / {
proxy_pass http://localhost:8081;
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 https;
}
}

server {
listen 80;
server_name nexus.example.com;
return 301 https://$host$request_uri;
}

✅ 3.重启 Nginx:

1
sudo systemctl restart nginx

然后访问:https://nexus.example.com 即可。


⚙️ 可选:配置 Nexus 接收 HTTPS Header(反向代理下)

确保 Nexus 能识别 HTTPS 代理,可以在 Nexus 管理后台设置:

  • 路径: Administration → Server Configuration → HTTP
  • Base URL: https://nexus.example.com

⚠️ m2.直接配置 Nexus 使用 SSL(不推荐)

Nexus 3 使用内嵌 Jetty Web Server,理论上可以通过修改 JVM 参数手动开启 HTTPS。但此方式 操作复杂、升级易失效

  1. 生成 Java keystore 文件(.jks):

    1
    2
    3
    keytool -genkeypair -alias nexus -keyalg RSA -keysize 2048 \
    -keystore keystore.jks -storepass password \
    -validity 3650 -dname "CN=nexus.example.com"
  2. 编辑 $NEXUS_HOME/etc/jetty/jetty-https.xml 启用 HTTPS connector(需要手动复制 Jetty 配置模板)

  3. 修改 $NEXUS_HOME/bin/nexus.vmoptions 添加:

    1
    2
    3
    -Djetty.ssl.port=8443
    -Djetty.ssl.keystore.path=/path/to/keystore.jks
    -Djetty.ssl.keystore.password=password
  4. 重启 Nexus

⚠️ 不推荐此方式,维护复杂且不支持热更新,官方推荐使用反向代理进行 HTTPS 接入


✅ 总结

方法 推荐程度 优点 缺点
🔁 反向代理(Nginx/Apache) ⭐⭐⭐⭐⭐ 灵活、安全、易配 需额外配置代理
🔒 Nexus 自带 Jetty SSL ⭐⭐ 独立运行 配置复杂,易错