1、http200,但是返回We’re sorry but XXXX doesn’t work properly without JavaScript enabled. Please enable it to continue.(项目1)
可能原因
server {
listen 80;
server_name localhost;
client_max_body_size 20m;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
add_header Access-Control-Allow-Origin *;
}
// 改动
location /dev-api/ {
proxy_pass http:www.baidu.com/dev-api;
add_header Access-Control-Allow-Origin *;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
改成
location /dev-api/ {
proxy_pass http:www.baidu.com/dev-api/;
add_header Access-Control-Allow-Origin *;
}
// 或者
location /dev-api {
proxy_pass http:www.baidu.com/dev-api;
add_header Access-Control-Allow-Origin *;
}
项目本地启动代理配置 vue.config.js
devServer:{
proxy: {
'/dev-api': {
target: 'http://www.baidu.com/dev-api,
ws: true,
secure: false,
changeOrigin: true,
pathRewrite:{
'^/dev-api':''
}
}
}
}
2、返回content-type是text/html (项目2)
原因:
nginx代理路径配置错误
… location /dev-api/ …
/dev-api/
配置错误,查看我本地的代理,发现这个项目的请求路径是api,后改成/api/
即可正常使用
项目本地启动代理配置
VUE_APP_PROXY = [["/proxy/api","http://www.baidu.com/dev-api"]
VUE_APP_GLOB_API_URL=/proxy
线上配置代理打包后,proxy应该被去掉
相当于
VUE_APP_PROXY = [["/api","http://www.baidu.com/dev-api"]
VUE_APP_GLOB_API_URL=