Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] Provide example of nginx reverse-proxy with context path #557

Open
cowwoc opened this issue Jan 27, 2025 · 0 comments
Open
Assignees

Comments

@cowwoc
Copy link

cowwoc commented Jan 27, 2025

The documentation at https://help.sonatype.com/en/docker-repository-reverse-proxy-strategies.html#nginx-host-mapping-reverse-proxy-example works well when nexus is running at the root of a server, but if there is a context path then it will not work.

The suggested configuration reads:

Docker /v2 and /v1 (for search) requests

location /v2 {
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";
proxy_pass http://nexus.example.com:8081/repository/docker-repo/$request_uri;
}
location /v1 {
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";
proxy_pass http://nexus.example.com:8081/repository/docker-repo/$request_uri;
}

Regular Nexus requests

location / {
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";
proxy_pass http://nexus.example.com:8081;
}

But if you have a context path /binaries with a docker repository called docker-proxy then the configuration needs to be:

Docker /v2 and /v1 (for search) requests

location /v2/binaries {
rewrite ^/v2/binaries/repository/docker-proxy/(.*)$ /binaries/repository/docker-proxy/v2/$1 break;

 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";
 proxy_pass http://nexus.example.com:8081/;

}
location /v1/binaries {
rewrite ^/v1/binaries/repository/docker-proxy/(.*)$ /binaries/repository/docker-proxy/v1/$1 break;

 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";
 proxy_pass http://nexus.example.com:8081/;

}

Regular Nexus requests

location /binaries {
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";
proxy_pass http://nexus.example.com:8081/binaries;
}

Please update the documentation to discuss this case. It is not intuitive to go from the existing example to the required configuration. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants