How do you redirect certain paths on an Nginx-hosted site from http to https?
I want to ensure everyone visiting the path "/admin" is behind https. Googling finds me several guides about how to add global rewrite rules, but I can't find anything about how to add a rewrite rule for a specific site.
All the examples I see for doing this use the server{}
syntax, which isn't allowed in a site's configuration file. What's the site-specific syntax equivalent?
I have a load balancer that accepts 443 connections, does all the SSL handling, and forwards requests to my server on port 80, do Nginx doesn't actually need to serve requests on port 443. It just needs to see that requests are originally coming from http and redirect the user to https. Previously, I was doing this redirect in Apache using a rewrite rule like:
RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
What's the equivalent in Nginx?