How can I redirect http to https and redirect second-level domain names to top-level domain names in the same nginx conf?
HTTP redirects to HTTPS (HTTPS listens to port 443. If you have multiple domain names on the same port, you need to set server_name)
server {
listen 80; server_name domain.com; rewrite ^(.*)$ https://$host permanent;
}
Second-level domain name redirects to top-level domain name:
listen 80; server_name *.domain.com; rewrite ^/(.*) http://domain.com/ permanent;
HTTP redirects to HTTPS (HTTPS listens to port 443. If you have multiple domain names on the same port, you need to set server_name)
server {
}
Second-level domain name redirects to top-level domain name:
server {
}