简体   繁体   English

无法使用EB单实例NodeJS NGINX Config将HTTP重定向到HTTPS

[英]Cannot Redirect HTTP to HTTPS with EB Single Instance NodeJS NGINX Config

I've been struggling all week trying to get http to https redirect working with elastic beanstalk's default single instance setup for nodejs while not behind a load balancer. 我整周都在努力尝试使http重定向到https重定向,并使用弹性beantalk的nodejs的默认单实例设置,而不是在负载均衡器后面。 I've created a .ebextensions/https-instance.config file (below) to setup https successfully and at the top have the port 80 redirect but it is not being recognized. 我创建了一个.ebextensions / https-instance.config文件(如下所示)以成功设置https,并在顶部将端口80重定向,但无法识别。 The site still allows http. 该站点仍允许使用http。

Is there no way to do this redirect with the .ebextensions? 没有办法使用.ebextensions进行此重定向吗? Do I really have to ssh into the server and get the existing config file and then override the whole thing as shown here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html ? 我是否真的必须通过SSH进入服务器并获取现有的配置文件,然后覆盖整个内容,如下所示: https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html

files:
  /etc/nginx/conf.d/http_custom_proxy.conf:
    mode: "000644"
    owner: root
    group: root
    content: |
      server {
        listen 80;
        return 301 https://$host$request_uri;
      }
  /etc/nginx/conf.d/https.conf:
     ...already working https code here

Try 尝试

files:
  "/etc/httpd/conf.d/ssl_rewrite.conf":
   mode: "000644"
   owner: ec2-user
   group: ec2-user
   content: |
       TraceEnable off
       RewriteEngine On
       <If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
       RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
       </If>

For https, you should redirect to 443 port. 对于https,您应该重定向到443端口。 that might be the problem 那可能是问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM