August 2017
Intermediate to advanced
278 pages
8h 53m
English
While a server block for each named site to redirect works perfectly, we can easily convert this back into a generic server block. This way, it's a simple configuration file between different sites and ensures that all other virtual servers on the same system also redirect.
server {
listen 80 default_server;
server_name _;
return 301 https://$server_name$request_uri;
}
Set default_server to the server block of any undefined server. The underscore (_) is simply a placeholder in NGINX; because we've set this server block to be the default, it will process all non-matching requests anyway. The underscore simply makes it easy to view.
Read now
Unlock full access