Nginx redirect all subdomains to main domain -



Nginx redirect all subdomains to main domain -

i'm trying redirect subdomains main domain, far isn't working. here's how i'm doing it:

server { hear [::]:80; server_name *.example.com; homecoming 301 $scheme://example.com$request_uri; } server { hear [::]:443; server_name example.com; ssl on; ssl_certificate /etc/ssl/certs/example.com.crt; ssl_certificate_key /etc/ssl/private/example.com.key; #enables versions of tls, not sslv2 or 3 weak , deprecated. ssl_protocols tlsv1 tlsv1.1 tlsv1.2; #disables weak ciphers ssl_ciphers "ecdhe-rsa-aes256-gcm-sha384:ecdhe-rsa-aes128-gcm-sha256:dhe-rsa-aes256-gcm-sha384:dhe-rsa-aes128-gcm-sha256:ecdhe-rsa-aes256-sha384:ecdhe-rsa-aes128-sha256:ecd$ ssl_prefer_server_ciphers on; root /var/www/html; index index.html; location / { # first effort serve request file, # directory, fall displaying 404. try_files $uri $uri/ =404; # uncomment enable naxsi on location # include /etc/nginx/naxsi.rules } }

however, when type e.g. www.example.com redirects https://www.example.com, how can redirect sub-domains https://example.com?

you can create default server, redirects https://example.com this:

server { hear [::]:80 default_server; server_name localhost; homecoming 301 https://example.com$request_uri; }

all incoming requests, don’t find matching server served default server, redirect them right domain.

redirect nginx

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -