javascript - how do i allow header "Accept-Ranges" in nginx? -
i have app working localhost:8888 using tornado, , headers i'v set:
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")
the app on localhot:8888 needs static file locahost:80, , nginx server on localhost:80 looks this:
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; }
but error in browser persistent:
refused unsafe header "accept-ranges"
i tried add headers above after seeing issue concerned op gave solution making static pdf server return headers
access-control-allow-headers: range access-control-expose-headers: accept-ranges, content-encoding, content-length,
how achieve in nginx , tornado?
for getting static file method need add access-control-allow-origin header nginx. have created following show how access static file cross origin.
i have created tornado server () hosts html file. trying access static file using javascript hosted nginx
tornado server.py
import tornado.web import tornado.ioloop class mainhandler(tornado.web.requesthandler): def get(self): self.render('index.html') if __name__ == '__main__': app = tornado.web.application([ (r'/', mainhandler) ]) app.listen(12303) tornado.ioloop.ioloop.instance().start()
index.html
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script> </head> <body> <p> hi </p> <button id="btn">click</button> <div id="content"></div> </body> <script> $(document).ready(function(){ $('#btn').click(function(){ $.get('http://localhost:12300/stacktest/abc.html', function(data){ $('#content').append(data); }); }); }); </script> </htm>
nginx configuration
server{ listen 12300; server_name localhost; location /stacktest { alias d:/stackof_test; index index.html; add_header access-control-allow-origin http://localhost:12303; } }
please note on windows , location "d:/stackof_test" contains file called "abc.html" following content
<p>got file</p>
Comments
Post a Comment