-1

I'm getting a 400 bad request.

This is the config code. file: staging.rewrites

if ($scheme = http) {
   return 301 https://$host:[port]$request_uri;
}

Does anyone know if this is a valid rewrite?

2 Answers2

1

I don't know where is your config file, although, I'd rather use the following lines in your 80 port to rewrite requests to port 443:

server {
    listen 80;

    server_name YOURSERVER_DOMAIN;

    access_log /var/log/nginx/access.http.log detailed;
    error_log /var/log/nginx/error.http.log notice;

    location / {
        rewrite ^ https://$host$request_uri? permanent;
    }
}

Regards

Alvaro Niño
  • 359
  • 2
  • 6
1

This is the preferred way to do http -> https redirect in nginx:

server {
    server_name example.com;

    return 301 https://www.example.com$request_uri;
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63