MENU

Nginx 反向代理 mvnrepository

October 10, 2020 • 技术分享

说明

由于国内访问 https://mvnrepository.com 频繁出现下图的情况

Snipaste_2020-10-10_09-41-29.png,故想起代理此站点;代理好的地址为:https://mvn.biuaxia.cn

nginx配置

下面贴出nginx的相关配置,仅供参考。

location~ * \. (php | jsp | cgi | asp | aspx) $ {
    proxy_pass https: //mvnrepository.com;
    proxy_set_header Host mvnrepository.com;
    proxy_set_header X - Real - IP $remote_addr;
    proxy_set_header X - Forwarded - For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE - HOST $remote_addr;
    proxy_ssl_server_name on;
}
location / {
    proxy_pass https: //mvnrepository.com;
    proxy_set_header Host mvnrepository.com;
    proxy_set_header X - Real - IP $remote_addr;
    proxy_set_header X - Forwarded - For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE - HOST $remote_addr;
    proxy_ssl_server_name on;

    add_header X - Cache $upstream_cache_status;

    #Set Nginx Cache

    add_header Cache - Control no - cache;
    expires 12h;
}

需要额外注意:

如果出现502,那是因为后端服务需要代理发送SNI(服务器名称TLS扩展)才能正常工作;如果代理服务器不发送SNI,会返回502错误。即无法正常和后端通信。

查找nginx官方文档,找到如下配置,nginx配置中增加:proxy_ssl_server_name on;

参考资料

ArchivesQR Code
QR Code for this page
Tipping QR Code
Leave a Comment

2 Comments
  1. 赞!前排混个脸熟,博客真好看@(吐舌)

    1. @茵荟养生资讯哈哈,不是博客好看,是主题好看。emm

      你的资讯站也不错呢~@(哈哈)