我有一个网站在Amazon ELB后面的EC2机器上运行。
我在ELB上配置了SSL,因此它为我处理http和https。 https上的所有请求都完美无缺。但我想强制(重定向)http请求到https。由于某种原因,它不起作用http to https重定向在nginx上
我在nginx中添加了重定向规则,但每当我启用该规则时,nginx服务器都会停止响应。
server {
listen 80;
server_name domain1.com;
gzip on;
gzip_proxied any;
gzip_types text/plain text/xml text/css application/x-javascript;
gzip_vary on;
access_log /var/log/nginx/domain1.access.log;
location/{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:4000/;
### Redirect http to https ####
if ($http_x_forwarded_proto != "https") {
rewrite ^(.*)$ https://$server_name$1 permanent;
}
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;";
}
}
请帮我在哪里,我与配置脚麻。 TIA。
是有你不能用任何理由'返回301个https://开头$主机$ REQUEST_URI;'? –