amazon-web-services - 如何在 Elastic Beanstalk 单实例环境中将 HTTP 重定向到 HTTPS
问题描述
我使用 Amazon Linux 2 在 Elastic Beanstalk 单实例环境中部署了一个 Spring Boot Web 应用程序。我已根据文档在 NGNIX 中配置了 SSL,并且所有 HTTPS 请求都工作正常。但是,HTTP 请求不会重定向到 HTTPS。下面是我的conf文件位于\PROJECT_ROOT\.platform\nginx\conf.d\https.conf
# HTTP server
server {
listen 80;
return 301 https://example.com$request_uri;
}
# HTTPS server
server {
listen 443 ssl;
ssl_certificate /etc/pki/tls/certs/server.crt;
ssl_certificate_key /etc/pki/tls/certs/server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
我创建了一条A 记录以映射example.com
到 EB 环境 URL。
但是,当我尝试点击http://example.com
它时,只需通过 HTTP 加载主页,而不是重定向到 HTTPS。
有人可以帮我吗?
解决方案
推荐阅读
- c# - 在 NetStandard2.0 项目中使用 Roslyn 编译动态创建的代码
- cassandra-2.0 - 如何在不指定分区键的情况下更新 cassandra 中的表?
- r - 如何将多个文本“节点”粘贴到一个文本中?
- cypress - cy.visit() 和 cy.request() 的不同 Cypress baseUrl
- javascript - 如何使用回调函数执行while循环
- mysql - 如何防止sequelizer删除数据库
- android - 带有 gl_FragDepth 的 Android 上 MonoGame 中的着色器问题
- python - 使用 Google API for Python - 没有下载凭据.json 文件的选项?
- css - 使用网格区域的响应式网格的媒体查询
- typescript - 使用 puppeteer 和 jest 进行测试时,canvas.getContext("webgl") 返回 null