GnoseedGnoseed
DevOps · Flashcard

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

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.

Read more in the docs
Study in Gnoseed →