gpt4 book ai didi

ssl - 如何重启 httpd 以在 Elastic Beanstalk 中的 EC2 实例上启用 HTTPS?

转载 作者:行者123 更新时间:2023-12-04 22:35:12 28 4
gpt4 key购买 nike

问题

我正在尝试在 Elastic Beanstalk 中的 EC2 实例上启用 HTTPS。我在 .ebextensions 目录中有一个 https-instance.config 文件,其中包括停止和启动 httpd 服务器。原始容器命令是这些(来自 AWS 文档 here ,并且在我的问题中也提到了 here :

container_commands:
01killhttpd:
command: "killall httpd"
02waitforhttpddeath:
command: "sleep 3"

但是,我收到以下错误,详细信息在 cfn-init.log 中:

2020-08-25 14:51:55,622 [INFO] -----------------------Starting build-----------------------
2020-08-25 14:51:55,631 [INFO] Running configSets: Infra-EmbeddedPostBuild
2020-08-25 14:51:55,634 [INFO] Running configSet Infra-EmbeddedPostBuild
2020-08-25 14:51:55,638 [INFO] Running config postbuild_0_tiny_app
2020-08-25 14:51:55,706 [ERROR] Command 01killhttpd (systemctl restart httpd.service) failed
2020-08-25 14:51:55,706 [ERROR] Error encountered during build of postbuild_0_tiny_app: Command 01killhttpd failed
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 260, in build
changes['commands'] = CommandTool().apply(self._config.commands)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/command_tool.py", line 117, in apply
raise ToolError(u"Command %s failed" % name)
ToolError: Command 01killhttpd failed
2020-08-25 14:51:55,706 [ERROR] -----------------------BUILD FAILED!------------------------
2020-08-25 14:51:55,707 [ERROR] Unhandled exception during build: Command 01killhttpd failed
Traceback (most recent call last):
File "/opt/aws/bin/cfn-init", line 171, in <module>
worklog.build(metadata, configSets)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 129, in build
Contractor(metadata).build(configSets, self)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 530, in build
self.run_config(config, worklog)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
CloudFormationCarpenter(config, self._auth_config).build(worklog)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 260, in build
changes['commands'] = CommandTool().apply(self._config.commands)
File "/usr/lib/python2.7/site-packages/cfnbootstrap/command_tool.py", line 117, in apply
raise ToolError(u"Command %s failed" % name)
ToolError: Command 01killhttpd failed

我已尝试从 https-instance.config 中删除此重新启动,它会构建但无法连接到 HTTPS。我还尝试用其他命令替换上述命令以重新启动 httpd 服务器,但这些命令导致的错误与上面的错误几乎相同:

container_commands:
01restart:
command: "systemctl restart httpd"

container_commands:
01restartservice:
command: "systemctl restart httpd.service"

问题

如何重新启动 httpd 服务器以允许 HTTPS 连接到我的应用程序?

上下文

  • 亚马逊 Linux 2
  • Python 3.7 环境中的 Flask 应用
  • 使用单个 EC2 实例,因此没有负载均衡器
  • 我只需要这个用于开发目的

这是我从 AWS 获得的完整 https-instance.config:

packages:
yum:
mod_ssl : []

files:
/etc/httpd/conf.d/ssl.conf:
mode: "000644"
owner: root
group: root
content: |
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/python/run/baselinenv
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On
Listen 443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/pki/tls/certs/server.crt"
SSLCertificateKeyFile "/etc/pki/tls/certs/server.key"

Alias /static/ /opt/python/current/app/static/
<Directory /opt/python/current/app/static>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias / /opt/python/current/app/application.py

<Directory /opt/python/current/app>
Require all granted
</Directory>

WSGIDaemonProcess wsgi-ssl processes=1 threads=15 display-name=%{GROUP} \
python-path=/opt/python/current/app \
python-home=/opt/python/run/venv \
home=/opt/python/current/app \
user=wsgi \
group=wsgi
WSGIProcessGroup wsgi-ssl

</VirtualHost>

/etc/pki/tls/certs/server.crt:
mode: "000400"
owner: root
group: root
content: |
-----BEGIN CERTIFICATE-----
MIID8zCCAtsCFGzyKrXOsCiyLHRPfBG75SlmQyXqMA0GCSqGSIb3DQEBCwUAMIG1
...
PuulTMAZWNXHa0g+XbRTtOQDA8FA0vlA80B+rFUQESSo2Cw5JKXTaL9OpMMG/t9S
qvv+vGuaIw==
-----END CERTIFICATE-----


/etc/pki/tls/certs/server.key:
mode: "000400"
owner: root
group: root
content: |
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA+OYzho7mXLUY6zTTqBIibsk2rfuJIO2xN2moIUNTqzJS8Yv6
...
cSQsBzRR1Z5hl77Qa6gwiDx7rYswWtQt/8zsY8OUB3kg1SqriwI=
-----END RSA PRIVATE KEY-----

container_commands:
01restartservice:
command: "systemctl restart httpd.service"

最佳答案

您的命令失败的原因是在 Amazon Linux 2 上Python 3.7 环境没有没有httpd(它是物理安装的,但不是事件的)。您可以通过 sshing 进入实例并运行来验证这一点:

sudo systemctl status httpd

相反,there are nginxgunicorn 作为 wsgi。您提供的 AWS 文档链接适用于 Amazon Linux 1,而不是 2。

因此,应该使用 nginx 设置 SSL 证书和 HTTPs config files.platform/nginx/conf.d/ 文件夹中。

关于ssl - 如何重启 httpd 以在 Elastic Beanstalk 中的 EC2 实例上启用 HTTPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63581996/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com