0

I'm trying to redirect all requests from http://blog.example.org to https://blog.example.org.

Unfortunately I receive this error:

400 Bad Request The plain HTTP request was sent to HTTPS port

My config:

server {
    listen      80;
    server_name blog.example.org;
    return 301 https://$host$request_uri$is_args$args;
}


server {
    server_name blog.example.org;
    listen 443 ssl http2;

    root /srv/www/wordpress;
    index index.php index.html index.htm;
Rob
  • 344
  • 3
  • 15
br0ken.pipe
  • 167
  • 2
  • 9

4 Answers4

2

I'm not completely sure, but I think the use of $is_args and $args is wrong here as $request_uri would contain the full request string (full URI path with arguments). Have you tried without those? Eg:

server {
    listen 80;
    server_name blog.example.org;
    return 301 https://$host$request_uri;
}
parkamark
  • 1,128
  • 7
  • 11
1

Your return statement is incorrect. You should have:

return 301 https://$server_name$request_uri;
Rob
  • 344
  • 3
  • 15
0

The redirect block should be:

server {
    listen      80;
    server_name blog.example.org;
    return 301 https://blog.example.org$request_uri;
}
Paul
  • 3,037
  • 6
  • 27
  • 40
-3

Try using rewrite, instead of return.

rewrite ^(.*) https://$host$1 permanent;

That's how it's done on our server. It may be a deprecated method, since it's been like this forever, but it works on nginx 1.10.0

edit: I was looking at the wrong problem. You need to add these directives to your ssl server configuration:

ssl on;
ssl_certificate /path/to/ssl/public/certificate.pem;
ssl_certificate_key /path/to/ssl/private/key.pem;
coladict
  • 219
  • 1
  • 7