Nginx – Redirect http subdomain to https

httphttpsnginxredirectsubdomain

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;

Best Answer

Your return statement is incorrect. You should have:

return 301 https://$server_name$request_uri;