我知道这个问题已被问过,但似乎没有任何工作对我来说。我试过多种不同的东西,比如在这些问题中描述的答案:Elastic Beanstalk Http重定向到Https
How to get Elastic Beanstalk nginx-backed proxy server to auto-redirect from HTTP to HTTPS? Redirecting EC2 elb from http to https
他们都不似乎工作。我是aws noob,所以我不完全确定如何编辑配置文件 - 或者如果我做错了什么。
我的设置如下:
- 路线53点弹性魔豆(Nginx的)
- ELB port configuration with ACM certificate(使用TCP/SSL,因为它使我的WebSockets工作)
- 端口8080 的NodeJS应用在我.ebextensions文件夹
我现在nginx.config文件(从this article得到这个):
files:
"/tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 8080;
set $fixedWWW '';
set $needRedir 0;
# nginx does not allow nested if statements
# check and decide on adding www prefix
if ($host !~* ^www(.*)) {
set $fixedWWW 'www.';
set $needRedir 1;
}
# what about that https? the traffic is all http right now
# but elastic load balancer tells us about the original scheme
# using $http_x_forwarded_proto variable
if ($http_x_forwarded_proto != 'https') {
set $needRedir 1;
}
# ok, so whats the verdict, do we need to redirect?
if ($needRedir = 1) {
rewrite ^(.*) https://$fixedWWW$host$1 redirect;
}
location/{
proxy_pass http://nodejs;
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;
}
gzip on;
}
但是,这似乎并没有做任何事情。我已经用完了想法。我不确定我是否错过了某个步骤,但我不知道该怎么做。作为一种解决方法,我的angularjs前端重定向了非https请求,但这太hacky,一些DOM在重定向之前呈现,我想重定向到负载平衡器 - 它应该重定向。
一目了然,你Nginx的配置看起来是正确的。它正在检查x-forward-proto头,如果不是“https”则重定向。它看起来像你也从裸体域重定向到www子域,是否工作?你确定nginx配置实际上是应用到你的beanstalk服务器吗? –
实际上,我刚刚在路由53中将裸域指向www,然后www指向EB。所以这个检查目前是多余的。我将如何检查此文件是否覆盖默认文件? – KDogg
[你做了什么KDogg](https://xkcd.com/979/)?我有同样的问题! –