Nexus3 + Nginx Reverse proxy
Asked Answered
C

1

6

I am trying to get Nexus3 to run behind Nginx.

Nginx is used as a reverse proxy and for SSL termination. When accessing the /nexus path through Nginx, I get multiple errors such as "Operation failed as server could not be reached" and "unable to detect which node you are connected to". Accessing the Nexus UI without going through Nginx works perfectly which lead me to think the error is on Nginx.

NginX Config File

location /nexus {
            proxy_pass http://localhost:8081/nexus/;
            proxy_set_header Host $host:$server_port;
            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;
            resolver 8.8.8.8 8.8.4.4 ipv6=off;
    }
Constanta answered 15/10, 2018 at 11:18 Comment(4)
When accessing the Nexus UI without going through Nginx, does the URI include the /nexus/ prefix?Ova
It works without going through Nginx i.e. accessing the URL on localhost:8081/nexus. The URI does contain the context path /nexus/ I am using Nginx for SSL termination.Constanta
Try: proxy_pass http://localhost:8081/nexus; (without a traling /) to match the location value. Also, try removing the Host header statement.Ova
Thanks Richard, that sorted out the issue. Please add as an answer so I may mark this as resolved.Constanta
O
5

If you access the service using http://localhost:8081/nexus, it works.

Your current configuration is using proxy_pass to change the URI /nexus to /nexus/. Generally, it is advisable to have a trailing / on both the location and proxy_pass URIs or on neither of them.

For example:

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

In fact, you do not need to modify the URI at all, so you can remove it from the proxy_pass directive altogether.

The following should be equivalent, but more efficient:

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

By default, the Host header is set to the value of the proxy_pass directive (i.e. localhost:8081), which is known to work correctly. You may find that your statement proxy_set_header Host $host:$server_port; is unnecessary.

See this document for details.

Ova answered 15/10, 2018 at 13:10 Comment(3)
I find, on Nexus OSS 3.15.2-01, that leaving out the Host header results in a 400 Bad Request. I have nginx listening on 8888 proxying to nexus at 8081.Millican
You're life saver!!! In ALL nginx examples of proxy_pass it's always strictly advisable to include trailing slash! But for god knows why reasons this doesn't work for Nexus, but the suggested efficient option worked perfectly! Thanks!Rahmann
I sunk hours into this until I found your answer. Thank you.Bevy

© 2022 - 2024 — McMap. All rights reserved.