You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx反向代理Nexus NuGet仓库无法加载服务索引问题

问题解决:Nginx转发NuGet代理仓库时的URL路径错误

问题原因

你的Nginx配置中,location /nuget对应的proxy_pass结尾缺少斜杠,导致URL转发时路径拼接错误。当请求https://nexusrepo.example.local/nuget/index.json时,Nginx会将其转发到http://nexus:8081/repository/nuget-proxyindex.json(丢失了关键的斜杠),从而无法正确访问Nexus的NuGet服务索引。

修复后的Nginx配置

修改location /nuget块的proxy_pass,在结尾添加斜杠:

server {
        listen 443 ssl;
        server_name nexusrepo.example.local;

        ssl_certificate /etc/nginx/certs/nexusrepo.example.local.pem;
        ssl_certificate_key /etc/nginx/certs/nexusrepo.example.local.key;
        
        location / {
            proxy_pass http://nexus:8081/;
            proxy_set_header Host $http_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 $scheme;
        }

        location /nuget {
            # 注意这里结尾添加了斜杠
            proxy_pass http://nexus:8081/repository/nuget-proxy/;
            proxy_set_header Host $http_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 $scheme;
        }
}

验证修复

修改配置后,重启Nginx容器:

docker restart nginx

然后重新执行之前报错的dotnet命令:

dotnet add package Polly --version 8.4.1 --source https://nexusrepo.example.local/nuget/index.json

此时应该能正常加载服务索引并安装NuGet包。

补充说明

Nginx的proxy_pass路径结尾斜杠的作用:

  • 如果proxy_pass结尾有斜杠,Nginx会将location匹配的路径前缀(这里是/nuget)替换为proxy_pass的路径(/repository/nuget-proxy/),最终转发路径为/repository/nuget-proxy/index.json
  • 如果没有斜杠,Nginx会直接将location的完整路径追加到proxy_pass后面,导致路径拼接错误

内容的提问来源于stack exchange,提问作者majidzandinia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 09:37:39