python - How to use send_static_file in Flask gunicorn nginx setup? -


i want call send_static_file, refers static html file, flask application. code works fine on localhost, when set nxingx , gunicorn error:

404 url not found error.

my flask app routes to:

from flask import flask flask.ext.sqlalchemy import sqlalchemy .frontend import frontend  application = flask(__name__, instance_relative_config=true)  application.register_blueprint(frontend, url_prefix='/app')  @application.route('/') def hello_world():     return "hello world" ------>>>>>this works     #return application.send_static_file('frontend/static/dist/index.html') ------>>>>>>>this not work 

my nginx config looks this:

server {     listen 80;     server_name 52.34.18.48;     error_log /var/www/appname/nginx_errorlog.log;     access_log /var/www/appname/nginx_accesslog.log;      root /var/www/appname;      location / {         proxy_pass http://127.0.0.1:8000;                 proxy_set_header host $host;                 proxy_set_header x-real-ip $remote_addr;                 proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;     } } 

when return string, string shown, when return static file content, error.

update 1:

running flask in debug returns:

  • running on http://127.0.0.1:5000/ (press ctrl+c quit) * restarting stat * debugger active!
  • debugger pin code: xxx-xxx-xxx 127.0.0.1 - - [29/jan/2016 04:09:20] "get / http/1.0" 200 - 127.0.0.1 - - [29/jan/2016 04:09:29] "get /app http/1.0" 301 - 127.0.0.1 - - [29/jan/2016 04:09:29] "get /app/ http/1.0" 404 -

what doing wrong here?

this function internally used flask. not suggest using in manner.

if need serve static files, suggest configuring nginx handle you. great in case of having parts of site high-performance!

if need use flask, @ send_from_directory. need.


Comments