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

Palvelin Postmaster postmaster at
Wed Sep 4 21:14:43 UTC 2019

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 apache to nginx. My apache currently 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"

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;
	real_ip_header X-Forwarded-For;
	server_name ”";
	root /var/www/;
	access_log /var/log/nginx/access-.log main_ext;
	error_log /var/log/nginx/error.log notice;

-- Hostmaster
postmaster at

More information about the nginx mailing list