【问题标题】:Python Flask webapp simple proxy configuration to enable SSL/HTTPS with ApachePython Flask webapp 简单的代理配置以使用 Apache 启用 SSL/HTTPS
【发布时间】:2012-11-30 01:42:28
【问题描述】:

我有一个基于 Python 的工作 web 应用程序,Flask。 (配置为在 http://host:port 上工作)

我需要让它与 https 一起工作。我得到了一个 Apache 代理 - 它以这种方式重定向所有请求:

(Apache) https://host/myApp --> http://host:port(我的基于 Flask 的应用程序)。 host:port 是我的应用正常运行的标准配置。

我能够访问服务和索引页面。但是,访问所有静态内容存在问题,这是 vi url_for 方法(如 ico、图像 等)请求的。

你能指出我的任何资源/信息吗?提前致谢。

【问题讨论】:

  • 您遇到了什么样的问题? 404错误?如果您手动键入静态资源的正确 url,添加 https,删除 s,会发生什么?哪个应用程序实际上为静态文件提供服务,Apache 或您的 Web 应用程序(可以两者兼有,但理想情况下是 Apache)。

标签: python apache web-applications proxy flask


【解决方案1】:

我们在 httpd.conf 中添加一行来处理 /static/ 而不是将其代理到 gunicorn:

<VirtualHost oursite.com>

  # Tells apache where /static/ should go
  Alias /static/ /full/path/to/flask/app/static/

  # Proxy everything to gunicorn EXCEPT /static and favicon.ico
  ProxyPass /favicon.ico !
  ProxyPass /static !
  ProxyPass / http://gunicorn.oursite.com:4242/
  ProxyPassReverse / http://gunicorn.oursite.com:4242/

</VirtualHost>

之所以有效,是因为我们在同一个盒子上运行了 gunicorn 和 apache,这可能对您有用,也可能不适用。作为站点部署的一部分,您可能必须将静态文件复制到 apache 主机。

可能有更好的方法,但它对我们有用。

【讨论】:

    猜你喜欢
    • 2018-04-19
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 2017-08-16
    • 2017-11-22
    • 1970-01-01
    相关资源
    最近更新 更多