我有一个使用龙卷风从 localhost:8888 运行的应用程序,这是我设置的标题:
def set_default_headers(self):
self.add_header("Access-Control-Allow-Origin", "*")
self.add_header("Access-Control-Expose-Headers","Accept-Ranges")
self.add_header("Access-Control-Expose-Headers","Content-Encoding")
self.add_header("Access-Control-Expose-Headers"," Content-Length")
self.add_header("Access-Control-Expose-Headers","Content-Range")
localhot:8888 上的应用需要从 locahost:80 获取静态文件,localhost:80 上的 nginx 服务器如下所示:
server {
listen 80;
server_name localhost;
root /var/www/statics;
passenger_enabled on;
passenger_use_global_queue on;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Origin [http://localhost:8888;]
add_header Access-Control-Expose-Headers Accept-Ranges;
add_header Access-Control-Expose-Headers Content-Encoding;
add_header Access-Control-Expose-Headers Content-Length;
add_header Access-Control-Expose-Headers Content-Range;
add_header accept_ranges bytes;
client_max_body_size 512M;
}
但浏览器中的错误是持久的:
Refused to get unsafe header "Accept-Ranges"
在看到这个问题后,我尝试在上面添加所有这些标题, 其中相关操作给出了他的解决方案,使静态 pdf 服务器返回标题
Access-Control-Allow-Headers: Range
Access-Control-Expose-Headers: Accept-Ranges, Content-Encoding, Content-Length,
我如何在 nginx 和龙卷风中实现这一点?