首页 > 解决方案 > 从 URL 中的子路径提供文件返回 CORS 请求未成功

问题描述

我正在尝试通过 Web 服务器提供一些矢量图块。用于呈现主页的主要文件正确提供,但瓷砖没有,浏览器给我这个错误,我猜是因为瓷砖位于子文件夹/tiles/中,如错误消息所示:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
http://my.server.org:8888/tiles/12/123/456.pbf. (Reason: CORS request did not succeed).

我很确定这是我的反向代理设置中的配置问题,但我无法弄清楚,我想知道为什么考虑到以下 nginx 配置,浏览器会继续在该 URL 中打印端口号:

server {
    listen 80;
    listen [::]:80;

    client_max_body_size 100M;
    charset utf-8;

    server_name my.server.org;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        include proxy_params;
        add_header Access-Control-Allow-Origin http://my.server.org;
        add_header Access-Control-Max-Age 3600;
        add_header Access-Control-Expose-Headers Content-Length;
        add_header Access-Control-Allow-Headers Range;
        proxy_pass http://127.0.0.1:8888/;
    }
}

另请注意,*.pbf 文件是由某些进程动态计算的,它们存储在服务器上。使用上述 URL 方案直接在其端点提供服务。

我有没有机会通过在 nginx 配置中设置我错过的东西来简单地解决这个问题?

标签: nginx

解决方案


推荐阅读