DevOps · Flashcard

What is the recommended way to redirect all HTTP traffic to HTTPS in nginx?

  • AA port-80 server that runs return 301 https://$host$request_uri to the client
  • BA port-80 server that runs rewrite ^ https://$host permanent without the path
  • CA port-443 server with an if block that checks the scheme on every request
  • DA global directive force_https on that upgrades every request automatically

Why this is the answer

A dedicated listen 80 server with return 301 https://$host$request_uri; is the clean, efficient redirect that preserves the path. The rewrite form drops $request_uri (losing the path), an if in the 443 server cannot catch plain-HTTP requests, and force_https is not a real nginx directive.

Official docs
Study in Gnoseed →