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;
  • What is the complete nginx configuration? What does nginx error.log tell? – Tero Kilkanen Sep 16 '16 at 11:53
1

Your return statement is incorrect. You should have:

return 301 https://$server_name$request_uri;
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;
}
0

The redirect block should be:

server {
    listen      80;
    server_name blog.example.org;
    return 301 https://blog.example.org$request_uri;
}
-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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.