Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nexus3 + Nginx Reverse proxy

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;
    }
like image 367
Taahir Hassem Avatar asked Oct 15 '18 11:10

Taahir Hassem


People also ask

How to configure Nginx reverse proxy for more than one repository?

If you have more than one hosted repository, create another Nginx reverse proxy for it, then aggregate them using a parent Nginx reverse proxy that forwards the request according to certain criteria (.i.e: Host header). All Nexus repositories must have consistent configuration of authentication: Either all require authentication, or all don't.

Is there a reverse proxy without connector ports from Nexus?

The following Nginx configuration file is for a reverse proxy without the need to expose connector ports from nexus : docker pull cregistry.example.com/myimage lets Nginx forward the request to "docker-group" docker push cregistry.example.com/myimage lets Nginx forward the request to "docker-hosted"

What is the use of Nginx/Nexus path?

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".

What is the hostname of the nginx Nexus Server?

Nexus hostname is "nexus.example.com" Your nginx (with the nginx.conf of this gist) will run for example under cregistry.example.com The following Nginx configuration file is for a reverse proxy without the need to expose connector ports from nexus :


1 Answers

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 so 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. locatlhost:8081), which is known to work correctly. You may find the your statement proxy_set_header Host $host:$server_port; is unnecessary.

See this document for details.

like image 65
Richard Smith Avatar answered Nov 03 '22 01:11

Richard Smith