python - Change static file serving to nginx from flask? -
i running flask project in nginx. conf file
server { listen 80; server_name site.in; root /root/site-demo/; access_log /var/log/site/access_log; error_log /var/log/site/error_log; location / { proxy_pass http://127.0.0.1:4000/; proxy_redirect http://127.0.0.1:4000 http://site.in; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-forwarded-proto $scheme; } }
when tried put expires part static files conf failed. read may due fact static files served flask rather nginx. if changes should bring above conf file static file serving can done nginx project.
as per answer changed conf below. static file shows 403 error.
server { listen 80; server_name site.in; root /root/site-demo/; access_log /var/log/site/access_log; error_log /var/log/site/error_log; location / { proxy_pass http://127.0.0.1:4000/; proxy_redirect http://127.0.0.1:4000 http://site.in; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-forwarded-proto $scheme; } location /static { alias /root/site-demo/static; autoindex on; expires max; } }
add nginx configuration:
location /static { alias /path/to/your/static/folder; autoindex on; expires max; }
edit
nginx requires whole tree readable , not root starts in nginx.conf. command
sudo chmod -r 777 /root/site-demo/static
should solve permissions problem. but, think, not thing - security reasons - put site in /root
directory of web server. site put under /var/www
folder.
p.s.
the chmod -r 777
command gives owner, group , others permission read, write , execute files in folder , in subfolders.
Comments
Post a Comment