A服务器:前端服务器(开放外网)B服务器:服务端服务器(未开发外网)需求:A服务器访问B服务器的文件
只需在A服务器上配置反向代理,转发到B服务器即可;具体配置如下:A服务器nginx配置:
#给出的file都没有匹配到,则重新请求最后一个参数给定的uri,就是新的location匹配
location ^~ /files/{
try_files $uri @new_uploads;
}
location @new_uploads{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://xxx.xx.xxx.xxx:9012;
}
B服务器的配置:
server {
listen 9012;
server_name localhost;
location ^~ /files/{
alias /home/file/;
#autoindex on;
index index.html index.htm;
}
}
重启nginx服务后
访问:A服务器IP:端口/file/xxx即可访问到B服务器/home/file/目录下的文件了。
参考:
https://blog.csdn.net/Answer0902/article/details/122996146
nginx访问另一台服务器上的文件



