近来遇到一个特殊情况,机房只有一台机器连接外网,但是希望内网能访问外网某个网站
(此网站是自己开发的)。
修改nginx的配置文件:
location /api/ {
proxy_pass https://www.abcd.cn/api/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
图片等资源也这么重定向
location /img/ {
proxy_pass https://www.abcd.cn/img/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
https://www.abcd.cn/api/; 是你的外网网址,也就是把vue的/api/请求全部重定向到外网,本来这个请求是发送给springboot后台处理。
然后把vue打包后的dist文件夹里面的所有内容,复制到nginx的html目录,启动nginx就可以啦。