Nginx: rewriting https:// to http://
Solution 1:
The cleaner, way would be:
if ( $scheme = "https" ) {
return 301 http://example.com$request_uri
or somewhere between that and Nathans answer, where your default ssl server block contains simply the return 301
(whichever ssl block it is, you'll have to take a close look at yours to see how its implemented and adapt) No point in doing regex for a simple redirect
return
- http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return
edit: i just noticed there is a variable $https
that can be used in the if statement instead. Returns " "
if not https:
if ( $https = "on" ) {
...
Keep in mind, while testing changes, you should use a 302
temporary redirect instead of 301
permanent, to save hair-pulling when you discover you fixed it an hour earlier but the changes didn't reflect in your browser :)