2014-04-04 53 views
1

我正在使用Gunicorn + Flask + Python开发一款Heroku应用程序,并且我希望能够与工头在本地运行它。它工作正常,但是当我切换到我的网站使用SSL时,它不再能够找到/静态下的javascript文件。我怎样才能使这些在HTTPS下可用?如何通过https为Gunicorn + Flask提供静态文件?

回答

0

你可以使用nginx的前端gunicorn?如果是这样,那么你可以通过添加一个位置块像下面的nginx.conf服务一样通过SSL的JavaScript静态内容:

server { 
    listen 443 ssl; 
    # other normal ssl stuff you seem to already have working 

    location/{ 
     root /path/to/your/static/stuff; 
     try_files $uri /index.html; # this will match your static content 
    } 
    location /api { 
     # your normal proxy stuff to gunicorn 
    } 
} 

而且分开,你可以提供静态内容从API分离通过HTTP的效率,像如下:

server { listen 80; location/{ try_files $uri /index.html; } } 
server { 
    listen 443 ssl; 
    # other normal ssl stuff you seem to already have working 
    location /api { 
     # your normal proxy stuff to gunicorn 
    } 
} 
+0

就这样 - 在同一页面上同时提供静态内容和安全内容将导致大多数浏览器显示某种安全警告。理想情况下,一切都应该在SSL下发生 - 静态内容或其他。 –