Vuepress跨域配置
# 开发环境调试时的配置
config.js配置
module.exports = {
//省略其他配置...
devServer: {
proxy: {
//匹配要跨域的请求
'/taoBaoKeApiTest': {
//要访问的跨域的域名
target: 'http://localhost:8080/',
ws: true,
secure: false, // 使用的是http协议则设置为false,https协议则设置为true
changOrigin: true,
pathRewrite: {
//要替换前缀时配置
'^/taoBaoKeApiTest': ''
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 线上环境
线上环境配置nginx转发
location /taoBaoKeApiTest {
proxy_pass [ip]:[port]/;
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_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
端口后的/
是必要的,以替换掉taoBaoKeApiTest
编辑 (opens new window)
上次更新: 2023/11/24, 15:09:25