【发布时间】:2021-08-05 03:25:17
【问题描述】:
我有一个托管一些数据的 docker 服务器。如果我导航到 URL,我可以看到数据没有问题。但是,当我运行 get axios 调用时,我收到了 CORS 错误。我需要在 Axios 中设置什么吗?
错误
Access to XMLHttpRequest at 'http://[myIP]:8080/myFile' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这里是 docker 文件
user nginx;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
server {
listen 80;
access_log /var/log/nginx/proxy.access.log main;
error_log /var/log/nginx/proxy.error.log debug;
location / {
root /data;
}
}
}
【问题讨论】:
-
这不是 dockerfile。它看起来像一个 nginx 配置。