【问题标题】:Nexus (3.2) Base URL is ignored?Nexus (3.2) 基本 URL 被忽略?
【发布时间】:2017-02-06 00:21:23
【问题描述】:

我可以毫无问题地在我的服务器上的 8081 端口运行 Nexus 3.2.0-01,但是我想以 https://HOST/nexus/ 的身份运行它,通过 nginx 反向代理。

根据文档,我需要设置我拥有的基本 URL 功能。然后我将它添加到我的 nginx 配置中:

location /nexus/ {
    proxy_pass http://localhost:8081/;

    # Rewrite HTTPS requests from WAN to HTTP requests on LAN                   
    proxy_redirect http:// https://;

    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";
}

这样做后,我可以访问 Nexus,但没有加载图像,没有加载 javascript,等等。查看 Chrome 的控制台,看起来 Nexus 想要访问 URL,例如:

https://HOST/static
https://HOST/service
https://HOST/repository

代替:

https://HOST/nexus/static
https://HOST/nexus/service
https://HOST/nexus/repository

我找不到任何方法来配置 Nexus 以全面利用基本 URL 功能。

我试过了:

  • 添加/删除 X-Forwarded-Proto
  • 将位置设置为 ^~ /nexus/
  • 启用和禁用 proxy_redirect

但是没有运气(不是我期望生成的 URL 引用 /nexus 基于 nginx 配置,我想不出其他可以尝试的方法)。

最后,我为 /static、/service 和 /repository 添加了 proxy_passes(假设我没有遗漏任何内容),乍一看它似乎可以工作,尽管我还没有尝试过发布或其他任何事情。

Nexus 无法正确使用基本 URL,我做错了什么?

【问题讨论】:

  • 你发现了吗?

标签: nginx nexus


【解决方案1】:

如果你在 nginx(或其他反向代理)后面运行 Dockerized 版本的 nexus3,你可以使用环境变量 NEXUS_CONTEXT 来设置新的上下文。

例如在我的 docker compose 中:

nexus:
   image: sonatype/nexus3:3.11.0
   ports:
     - 8081:8081
   networks:
     - my_net
   environment:
      NEXUS_CONTEXT: nexus

【讨论】:

    【解决方案2】:

    如果您想在“/”以外的上下文路径上运行 Nexus,您必须调整 Nexus 实际运行的上下文路径。编辑“sonatype-work/nexus3/etc/nexus.properties”并设置“nexus-context-path=/nexus”。请参阅此处了解我们的其他建议:

    http://books.sonatype.com/nexus-book/reference3/index.html

    【讨论】:

    【解决方案3】:

    基本路径应该匹配 nginx 和 nexus。为此,您应该通过设置 ENV NEXUS_CONTEXT 来更改 nexus.properties 上的 nexus-context-path。

    我已经使用 Helm 图表在 Kubernetes 上部署了 nexus,但实际上应该是相同的。

    如果您使用的是 helm chart,您可以将其添加到您的 values.yaml 中

    nexus:
      env:
        - name: NEXUS_CONTEXT
          value: nexus
    

    这是完整的 values.yaml

    sonatype-nexus:
      statefulset:
        enabled: true
      nexusProxy:
        env:
          nexusDockerHost: mydocker.example.com
          nexusHttpHost: mynexus.example.com
          additionalNexusHost: mynexus3.example.com
      nexus:
        env:
          - name: install4jAddVmParams
            value: "-Xms1200M -Xmx1200M -XX:MaxDirectMemorySize=2G -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
          - name: NEXUS_CONTEXT
            value: nexus
        resources:
          limits:
            cpu: 3
            memory: 5Gi
          requests:
            cpu: 250m
            memory: 4Gi
        readinessProbe:
          path: /nexus
        livenessProbe:
          path: /nexus
        service:
          type: ClusterIP
        securityContext:
          fsGroup: 2000
      persistence:
        storageClass: ssd
        storageSize: 20Gi
      ingress:
        enabled: false
    

    为方便起见,我禁用了 Helm 图表入口,但您可以根据需要使用它。不过,我的入口是这样的:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/proxy-body-size: "0"
      labels:
        app: sonatype-nexus
        heritage: Tiller
        release: nexus
      name: nexus-sonatype-nexus
    spec:
      rules:
      - host: mynexus.example.com
        http:
          paths:
          - backend:
              serviceName: nexus-sonatype-nexus
              servicePort: 8080
            path: /nexus
      - host: mynexus3.example.com
        http:
          paths:
          - backend:
              serviceName: nexus-sonatype-nexus
              servicePort: 8080
            path: /nexus
      - host: mydocker.example.com
        http:
          paths:
          - backend:
              serviceName: nexus-sonatype-nexus
              servicePort: 8080
            path: /
      tls:
      - hosts:
        - mynexus.example.com
        - mydocker.example.com
        - mynexus3.example.com
        secretName: wildcard-example-com
    

    【讨论】:

    • 你能分享你的完整 vaules.yaml 吗?我无法处理这个。
    • @hokwang 抱歉耽搁了,这是我使用的完整 values.yaml。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 2015-01-24
    • 2014-09-28
    相关资源
    最近更新 更多