Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https-redirect-nodejs.config not working on new platform #132

Open
tamslinn opened this issue Jun 28, 2020 · 3 comments
Open

https-redirect-nodejs.config not working on new platform #132

tamslinn opened this issue Jun 28, 2020 · 3 comments

Comments

@tamslinn
Copy link

I put the file https-redirect-nodejs.config into .ebextensions and confirmed this was part of the deployment archive, but it had no effect - http was not redirected to https.

I think the file is executed and creates a file in /etc/nginx/conf.d as required but then later in the deployment the directory is overwritten.

I got it to work by placing the contents of the file which would have been written by https-redirect-nodejs.config into .platform/nginx/conf.d/https-redirect-nodejs.conf

I wonder if the instructions need updating for new platform versions?

@Gr8z
Copy link

Gr8z commented Jun 30, 2020

Could you send me that file? @tamslinn

I am struggling to get this to work.

@tamslinn
Copy link
Author

tamslinn commented Jul 6, 2020

Apologies I missed your comment. This is what I put in .platform/nginx/conf.d/https-redirect-nodejs.conf. I just took this from https-redirect-nodejs.config in this repository.

Note I had to make sure the node app I was deploying was listening on 8081

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

server {
   listen 8080;


   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;

}```

@bnbon
Copy link

bnbon commented Dec 13, 2020

Anyone else having this issue? The post above is invalid, I tried correcting the obvious flaws, but couldn't get it to work either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants