Monday, 15 April 2013

python - How to implement SSL(http to https) using Flask, Flask-SocketIO and nginx -



python - How to implement SSL(http to https) using Flask, Flask-SocketIO and nginx -

my application uses flask-socketio, flask , nginx. read in post http https handling must done @ web server level , not @ application server level. used rewrite attribute redirect http requests https requests. works static pages. however, when seek load dynamic content, error stating the page @ 'https://localhost/myloc' loaded on https, displayed insecure content 'http://localhost/myloc/more/paths?t=1390397': content should loaded on https..

further error xmlhttprequest cannot load http://localhost/myloc/more/paths?t=1390397. no 'access-control-allow-origin' header nowadays on requested resource. origin 'https://localhost' hence not allowed access.

my nginx.conf file looks this

server { server { hear 80; server_name _; rewrite ^ https://$host$request_uri? permanent; } server { gzip on; ssl on; hear 443 ssl; server_name *.mydomain.com; ssl_certificate /path/to/nginx/ssl/nginx.crt; ssl_certificate_key /path/to/nginx/ssl/nginx.key; location /myloc { proxy_pass http://localhost:9001/myloc; proxy_redirect off; proxy_buffering off; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } }

please help. flask-socketio must contain paths certificate , key?

try this:

location /myloc { proxy_pass https://localhost:9001/myloc; proxy_redirect off; proxy_buffering off; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; add_header access-control-allow-origin *; }

but https offload prefer way, proxy_pass http:// directive better, helps nginx response backend possible , close connection. requirement have backend (which listens port 9901) serve http.

python nginx flask openssl flask-socketio

No comments:

Post a Comment