nginxreverse-proxynexus3

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

Solution

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