I want to ask about HTTP-to-HTTPS
redirections. As we know WWW-to-none-WWW
redirections happen by redirecting from the web server side. But when it comes to the https redirection, it can be done by both ways, server-side ( Nginx etc...
) and application-side ( Middleware
). I want to know:
top-level
domains and sub-domain
domains on the same server.Thank you.
Reference:
Server-based redirection here should be more performant because it happens before any application code gets loaded.
Personally, I always do this in the nginx server{} block for all sites. I create a conf file for a domain and have 2 server{} blocks, a main one listening on 443 for HTTPS traffic, and a small one that just recognises the (sub)domain and does a redirect to the HTTPS protocol.
Here's an example redirect server{} block I have for a particular subdomain:
server {
server_tokens off;
listen 80;
server_name sub.domain.com;
return 301 https://sub.domain.com$request_uri;
}
As for pros cons for server-based, the obvious ones I would say are:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.