vue 服务端为node,已开启cors跨域支持,请求报Network Errorat,如何解决...
发布网友
发布时间:2022-04-23 18:21
我来回答
共1个回答
热心网友
时间:2022-04-10 19:55
有可能是后端nginx配置问题,或者前端页面是https,但是接口是http,也会引起network error,这里给你一份简单的nginx配置参考,root是vue编译文件存放目录,自行修改成你们服务器上的。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 20m;
server {
listen 80;
gzip on;
gzip_buffers 32 4K;
gzip_comp_level 6;
gzip_min_length 100;
gzip_types application/javascript text/css text/xml;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
}