[英]Redirect HTTP to HTTPS (Middleware redirect vs Nginx)
I want to ask about HTTP-to-HTTPS
redirections.我想问一下HTTP-to-HTTPS
重定向。 As we know WWW-to-none-WWW
redirections happen by redirecting from the web server side.正如我们所知, WWW-to-none-WWW
重定向是通过从 Web 服务器端重定向来发生的。 But when it comes to the https redirection, it can be done by both ways, server-side ( Nginx etc...
) and application-side ( Middleware
).但是当涉及到 https 重定向时,它可以通过服务器端( Nginx etc...
)和应用程序端( Middleware
)两种方式来完成。 I want to know:我想知道:
top-level
domains and sub-domain
domains on the same server.考虑同一服务器上的多个top-level
域和sub-domain
域的每种方式的优缺点。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.就我个人而言,我总是在所有站点的 nginx server{} 块中执行此操作。 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.我为域创建了一个 conf 文件,并有 2 个服务器块,一个主要用于侦听 443 以获取 HTTPS 流量,一个小块仅识别(子)域并重定向到 HTTPS 协议。{}
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:至于基于服务器的利弊,我想说的显而易见的是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.