【发布时间】:2016-06-19 10:42:34
【问题描述】:
我知道以前有人问过这个问题,但似乎没有什么对我有用。我尝试了多种不同的方法,例如这些问题中描述的答案:
How to get Elastic Beanstalk nginx-backed proxy server to auto-redirect from HTTP to HTTPS? Redirecting EC2 elb from http to https
它们似乎都不起作用。我是个新手,所以我不完全确定编辑配置文件的工作原理——或者我是否做错了什么。
我的设置如下:
- Route 53 指向 Elastic Beanstalk (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-forwarded-proto 标头,如果不是“https”则重定向。看起来您也在从裸域重定向到 www 子域,这有效吗?您确定 nginx 配置实际上已应用于您的 beanstalk 服务器吗?
-
我实际上只是将裸域指向路由 53 中的 www,然后 www 指向 EB。因此,该检查目前是多余的。如何检查此文件是否覆盖默认文件?
-
What did you do KDogg??我也有同样的问题!
-
我从来没有真正弄清楚该怎么做:P 我只是在我的 html 文件头部的第一个标记中放置了一个 javascript 重定向。它足够快,不会真正影响加载时间。对不起!如果你弄清楚了,我很想知道
标签: amazon-web-services nginx https amazon-elastic-beanstalk amazon-elb