Welcome! Log In Create A New Profile

Advanced

How to redirect to https when using load balancer in front of nginx

Palvelin Postmaster
September 04, 2019 05:08PM
I have AWS ALB in front of an instance running nginx. I want to terminate https at the load balancer.

I have setup ALB's http listener to redirect http to https and forward https to the instance’s port 80.

I’m switching from using apache2 to nginx. My apache responds on a single port 80. In my apache config these directives are used to redirect traffic.

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
SetEnv HTTPS "on"
SetEnv HTTP_X_FORWARDED_PROTO ”https”

As simple as it may be, I can’t figure out how to match this setup with nginx. With the following simple config most requests work but apparently assets in some of my pages have the scheme hardcoded and they don’t get rewritten.

server {
listen 80;
set_real_ip_from 172.31.0.0/16;
real_ip_header X-Forwarded-For;
server_name ”my.server.com";
root /var/www/;
access_log /var/log/nginx/access-.log main_ext;
error_log /var/log/nginx/error.log notice;
}

--
Hans Vallden
VP of Business Development | Vincit California
(949) 241-1151

vincit.com | vincitdevtalks.com
proud member of codedinoc.com



_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to redirect to https when using load balancer in front of nginx

Palvelin Postmaster September 04, 2019 05:08PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 180
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready