Elastic Beanstalk 重定向缺少冒号?

dhj*_*dhj 5 nginx amazon-web-services amazon-elastic-beanstalk

我在 Elastic Beanstalk 中设置了一个网站,但是当我website.com在浏览器中输入 URL 时,它会自动将我定向到https//website.com并且缺少冒号...如果我添加 www.website.com 则它会起作用...或者如果我键入https://www.website.com

.ebextensions/prod01.config文件的内容

files:
  /etc/nginx/conf.d/proxy.conf:
    owner: root
    group: root
    mode: "000644"
    content: |
      # Elastic Beanstalk Managed

      # Elastic Beanstalk managed configuration file
      # Some configuration of nginx can be by placing files in /etc/nginx/conf.d
      # using Configuration Files.
      # http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/customize-containers.html 


      upstream nodejs {
          server 127.0.0.1:8081;
          keepalive 256;
      }

      server {
          listen 8080;
          server_name website.com;

          if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
              set $year $1;
              set $month $2;
              set $day $3;
              set $hour $4;
          }
          access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
          access_log  /var/log/nginx/access.log  main;

          location / {
              set $redirect 0;
              if ($http_x_forwarded_proto != "https") {
                set $redirect 1;
              }

              if ($http_user_agent ~* "ELB-HealthChecker") {
                set $redirect 0;
              }

              if ($redirect = 1) {
                return 301 https://www.heyants.com$request_uri;
              }

              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;
          }
      }

      server {
          listen 8080;
            server_name www.website.com;

          if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
              set $year $1;
              set $month $2;
              set $day $3;
              set $hour $4;
          }
          access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
          access_log  /var/log/nginx/access.log  main;


          location / {
              set $redirect 0;
              if ($http_x_forwarded_proto != "https") {
                set $redirect 1;
              }

              if ($http_user_agent ~* "ELB-HealthChecker") {
                set $redirect 0;
              }

              if ($redirect = 1) {
                return 301 https://$host$request_uri;
              }

              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;
      gzip_comp_level 4;
      gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

      }
  /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
    owner: root
    group: root
    mode: "000755"
    content: |
      #!/bin/bash -xe
      rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
      if [[ -e /etc/init/nginx.conf ]] ; then
        echo Using initctl to stop and start nginx
        initctl stop nginx || true
        initctl start nginx
      else
        echo Using service to stop and start nginx
        service nginx stop 
        service nginx start
      fi

container_commands:
  removeconfig:
    command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"
Run Code Online (Sandbox Code Playgroud)

更新

我已更新为使用下面提供的 AWS 参考资料之一;但重定向的一个条件仍然不起作用;我希望通过这次明确的更新,可以为所有人找到真正规范的解决方案。

abd*_*wer 0

根据您的要求,使用以下内容更新位于“/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf”的 AWS Elastic Beanstalk 配置文件:

location / {
    set $redirect 0;
    if ($http_x_forwarded_proto != "https") {
        set $redirect 1;
    }
    if ($http_user_agent ~* "ELB-HealthChecker") {
        set $redirect 0;
    }
    if ($redirect = 1) {
        return 301 https://$host$request_uri;
    }

    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;
}
Run Code Online (Sandbox Code Playgroud)