[英]redirect 81 to 443 in nginx
I'm trying to get all traffic served as https. 我正在尝试将所有流量都用作https。 However the server is behind a AWS ELB.
但是,服务器在AWS ELB后面。 So I've setup a listener on the ELB to direct 80 -> 81 and 443 -> 80 ie all http traffic goes to port 81 on the rails server.
因此,我在ELB上设置了一个侦听器,以将80-> 81和443-> 80定向为直接将所有http流量发送至rails服务器上的端口81。 And all https traffic goes to port 80 (ssl terminated on the ELB) I'm trying to get nginx to redirect all port 81 traffic to https.
而且所有https流量都流向端口80(ELB上终止的ssl),我试图让nginx将所有端口81流量重定向到https。 Seems simple enough.
似乎很简单。
So I have a server block called redirect_to_ssl in the sites_available directory it looks like this: 所以我在sites_available目录中有一个名为redirect_to_ssl的服务器块,它看起来像这样:
server {
listen 81;
server_name redirect_to_ssl;
return 301 https://$hostname$request_uri;
}
I've symlinked this file into sites-enabled 我已将此文件符号链接到启用了站点的文件中
And I've reloaded the config for nginx 我已经重新加载了nginx的配置
But when I try and curl localhost:81 I get connection refused. 但是,当我尝试卷曲localhost:81时,连接被拒绝。 And when I try and browse the site from outside the ELB, it does nothing
当我尝试从ELB外部浏览该站点时,它什么也没做
Any ideas? 有任何想法吗? Is there another way of doing what I'm trying to do with AWS ELB's ?
是否有另一种方法可以处理AWS ELB?
Directive server_name
is not a label, it's the name of the virtual server, ie its value must match with HTTP Host header of ingoing requests for the server block to be accessed. 指令
server_name
不是标签,它是虚拟服务器的名称,即其值必须与正在访问的要访问的服务器块的请求的HTTP Host标头匹配。 So it will likely never match any Host actual host header in use with your setup and never be reached. 因此,它可能永远不会与设置中使用的任何主机实际主机头匹配,也永远不会达到。
Read the documentation . 阅读文档 。
The use of $hostname
is also weird if you use a load balancer ... 如果使用负载均衡器,则
$hostname
的使用也很奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.