0

I am trying to redirect non-www requests to www, but it appears that either my Nginx config is not running the redirect in the below server block or the fact that SSL is enabled, but not for the non-www site is blocking the redirect from happening.

The following is in place which makes me think the setup is correct, but I noticed the following scenarios:

The following are in place:

  • I have name certificates for www.example.com and .example.com
  • www.example.com A ALIAS "my-elasticbeanstalk-address"
  • example.com A ALIAS "www.example.com record"

And here is my config (redirecting http requests to https and www):

# 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
#
# Modifications of nginx.conf can be performed using container_commands to modify the staged version
# located in /tmp/deployment/config/etc#nginx#nginx.conf

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

server {
    listen 8080;
    if ($http_x_forwarded_proto = "http") { return 301 https://www.$host$request_uri; }




    location / {
        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/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascri$

}

Am I missing something? Should the server block be a different setup?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.