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

4 Answers 4

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; 
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.