I can run Nexus 3.2.0-01 on my server at port 8081 without a problem, however I would like to run it as https://HOST/nexus/, reverse proxied through nginx.
According to the documentation, I need to set a Base URL capability, which I have. I then added this to my nginx configuration:
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";
}
After doing so, I can access Nexus but no images load, the javascript doesn't load, etc. Viewing Chrome's console, it looks like Nexus wants to access URLs such as:
https://HOST/static
https://HOST/service
https://HOST/repository
instead of:
https://HOST/nexus/static
https://HOST/nexus/service
https://HOST/nexus/repository
I can't find any way to configure Nexus to actually leverage the Base URL capability across the board.
I have tried:
But no luck (not that I expected the generated URLs to reference /nexus based on the nginx configuration, I couldn't think of anything else to try).
Finally, I added proxy_passes for /static, /service, and /repository (assuming I'm not missing any) and at first glance it appears to work, though I haven't tried publishing or much else yet.
What am I doing wrong that Nexus won't use the Base URL properly?
In case you are runnig a Dockerized version of nexus3 behind nginx (or other reverse proxy) you can use the environment variable NEXUS_CONTEXT to set the new context.
For example in my docker compose:
nexus:
image: sonatype/nexus3:3.11.0
ports:
- 8081:8081
networks:
- my_net
environment:
NEXUS_CONTEXT: nexus
If you want to run Nexus on a context path other than "/" you must adjust the context path Nexus is actually running on. Edit "sonatype-work/nexus3/etc/nexus.properties and set "nexus-context-path=/nexus". See here for our other recommendations:
http://books.sonatype.com/nexus-book/reference3/index.html
The base path should match for both, nginx and nexus. For this to work, you should change the nexus-context-path on nexus.properties by setting the ENV NEXUS_CONTEXT.
I have deployed nexus on Kubernetes using its Helm chart, but it should be practically the same.
If you are using the helm chart, you can add this to your values.yaml
nexus:
env:
- name: NEXUS_CONTEXT
value: nexus
Here is the full 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
I disabled the Helm chart ingress for my convenience, but you can use it if you want to. Nevertheless, here is how my ingress looks:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With