我是 AWS、Elastic Beanstalk、Apache 和 Flask 的新手。
我正在尝试纯粹通过 HTTPS 为我的 Web 应用程序提供服务。
我提供了我所做的一切细节,希望有人能找到我遗漏或做错的事情。
AWS 设置
我正在使用 AWS Elastic Beanstalk,使用 Amazon Linux AMI,并在最新的 Python 容器 (Python 3.4) 中使用 Flask 和 Flask-Security(处理用户/ session )编写我的应用程序。
我做了什么
option_settings
之外没有其他特殊配置在我的配置文件中 .ebextensions
项目根目录下。我用它来配置我的 WSGIPath(在那里我暴露了我的 application
可调用)和静态文件:option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: my_app.wsgi
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "my_app/static/"
"/favicon.ico": "my_app/static/img/favicon.ico"
.ebextensions
添加自定义配置AWS 提供的机制。我加了一个 RewriteRule
对于所有不是通过 https 进入的流量,通过 https 重定向。我还为端口 443 添加了一个新的 VirtualHost 并添加了我所有的原始映射(从上面开始,刚刚转换为 Apache 配置)。我的 SSL 配置文件如下:files:
"/etc/httpd/conf.d/ssl.conf":
mode: "000644"
owner: root
group: root
content: |
<VirtualHost *:80>
LogLevel debug
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
</VirtualHost>
<VirtualHost *:443>
LogLevel debug
Alias /favicon.ico /opt/python/current/app/my_app/static/img/favicon.ico
<Directory /opt/python/current/app/my_app/static/img/favicon.ico>
Order allow,deny
Allow from all
</Directory>
Alias /static/ /opt/python/current/app/my_app/static/
<Directory /opt/python/current/app/my_app/static/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /opt/python/current/app/my_app.wsgi
<Directory /opt/python/current/app/>
Require all granted
</Directory>
</VirtualHost>
container_commands:
restart_apache:
command: /sbin/service httpd restart
<VirtualHost *:443>
指令删除,我只得到一个空白的“/索引”网页。 我希望我的整个网站都通过 HTTPS 提供服务。许多 SO 文章和其他网站指出了如何配置 Elastic Load Balancer 以接受 HTTPS 并转发到 EC2 实例上的端口 80 (HTTP),但是我必须遗漏一些东西 - 好像我的 Apache 服务器没有发送出站流量HTTPS。
因此,我查看了 Apache 配置并注意到了 RewriteRule 指令,该指令将端口 80 流量重定向到端口 443,但许多建议使用 RewriteRule 的网站也忘记提及我可能需要为端口 443 设置新的 VirtualHost。
同样,我不确定我是否遗漏了一些关键的东西(显然我的理解存在差距) - 但我似乎无法找到一种方法让我的整个网站通过 HTTPS 运行。
提前致谢。
最佳答案
我的问题在于我如何配置端口。获得证书后,您可以在配置 > 负载均衡器 > 修改中配置您的端口。
这是我的配置:
这个资源对我非常有用,如果你需要它会提供更多细节:https://colintoh.com/blog/configure-ssl-for-aws-elastic-beanstalk
关于python - 如何在 AWS Elastic Beanstalk 上设置 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30451543/