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

Not working docker https-redirect #131

Open
ariel-frischer opened this issue Jun 27, 2020 · 6 comments
Open

Not working docker https-redirect #131

ariel-frischer opened this issue Jun 27, 2020 · 6 comments

Comments

@ariel-frischer
Copy link

ariel-frischer commented Jun 27, 2020

I've added the file: https-redirect-docker-sc.config (I've also just tried the node file separately)
into my .ebextensions folder and configured my single container docker instance load balancer to handle https correctly as the docs (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-elb.html) have explained. However the http requests are simply not being redirected and I can't find any error messages in the logs either.
I hope this is updated and working for Docker running NodeJS Linux 2/3.0.3 .

@rafalantas
Copy link

hi,

same for me. It was working fine before update to AMI 2. it is reflecting Apache setings not ngnix

@miguelaferreira
Copy link

I've worked around this issue by grabbing the /etc/nginx/nginx.conf from an environment, adding the redirect configuration to it (as described in https-redirect-docker-sc.config), and placing that file under .platform/nginx/nginx.conf so it overwrites the default file.

Basically I've made the location / of the default file look like this

           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://docker;
               proxy_http_version    1.1;
       
               proxy_set_header    Connection            $connection_upgrade;
               proxy_set_header    Upgrade                $http_upgrade;
               proxy_set_header    Host                $host;
               proxy_set_header    X-Real-IP            $remote_addr;
               proxy_set_header    X-Forwarded-For        $proxy_add_x_forwarded_for;
           }

@nullRefErr
Copy link

@ariel-frischer Is your issue solved ? Did you find any solution ?

@ramiglez30
Copy link

Same here, deployments run well using https-redirect-docker-sc.config but not redirection is made.
I have also tried to overwrite directly into .platform/nginx/sites-available/elasticbeanstalk-nginx-docker-proxy.conf

@ramiglez30
Copy link

@miguelaferreira can you please share the default config file with the adjustment? Thanks

@choychris
Copy link

@ramiglez30 if you still looking for the file
I made it work with miguelaferreira's work around.
Copy all content from /etc/nginx/nginx.conf in your ec2 instance, only replace the location / part with https-redirect-docker-sc.config

Here is the nginx.conf after change:

# Elastic Beanstalk Nginx Configuration File

user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
worker_rlimit_nofile    200000;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log    /var/log/nginx/access.log;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

    include  conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
            default       "upgrade";
    }

    server {
        listen 80 default_server;
        gzip on;
        gzip_comp_level 4;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        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://docker;
            proxy_http_version    1.1;

            proxy_set_header    Connection             $connection_upgrade;
            proxy_set_header    Upgrade                $http_upgrade;
            proxy_set_header    Host                   $host;
            proxy_set_header    X-Real-IP              $remote_addr;
            proxy_set_header    X-Forwarded-For        $proxy_add_x_forwarded_for;
        }

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }
}

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

6 participants