Report this

What is the reason for this report?

Nginx has redirect loop when trying to redirect to https

Posted on February 22, 2016

example.com is my site’s url.

It has a redirect loop on the line where it redirects to https.

Any fix?

Also how would I hide the PHP extension?

I have nginx 1.9.3 on ubuntu.

server {
	listen 80 default_server;
	root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.php;

	server_name example.com;
	return 301 https://example.com$request_uri; # Where it loops
	
	error_page 500 /500.html;
	error_page 404 /404.php;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
		
		#htacess stuff
				
	}
}


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Change

return 301 https://example.com$request_uri; to return 301 https://$server_name$request_uri;

And where is your 443 listen? You can’t point to https if you didn’t set it up :)

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.