i do both www A record and nginx redirect as it won't work if you don't resolve www via DNS
.07 betas menu option 2 used to create Nginx vhosts already has a commented out template for non-www redirect to www i.e. add domain1.com via centmin.sh menu option 2 Code: -------------------------------------------------------- Centmin Mod 1.2.3-eva2000.07 - http://centminmod.com -------------------------------------------------------- Centmin Mod Menu -------------------------------------------------------- 1). Centmin Install 2). Add Nginx vhost domain 3). NSD setup domain name DNS 4). Nginx Upgrade / Downgrade 5). PHP Upgrade / Downgrade 6). XCache Re-install 7). APC Cache Re-install 8). XCache Install 9). APC Cache Install 10). Memcached Server Re-install 11). MariaDB 5.2, 5.5, 10 Upgrade Sub-Menu 12). Zend OpCache Install/Re-install 13). Install ioping.sh vbtechsupport.com/1239/ 14). SELinux disable 15). Install/Re-install ImageMagick PHP Extension 16). Change SSHD Port Number 17). Multi-thread compression: pigz,pbzip2,lbzip2,p7zip etc 18). Suhosin PHP Extension install 19). Install FFMPEG and FFMPEG PHP Extension 20). NSD Re-install 21). Update - Nginx + PHP-FPM + Siege 22). Exit -------------------------------------------------------- Enter option [ 1 - 22 ] 2 -------------------------------------------------------- --------------------------------------------- Enter vhost domain name you want to add (without www. prefix): domain1.com --------------------------------------------- nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful Reloading nginx: [ OK ] --------------------------------------------- vhost for domain1.com created successfully vhost conf file for domain1.com created: /usr/local/nginx/conf/conf.d/domain1.com.conf upload files to /home/nginx/domains/domain1.com/public vhost log files directory is /home/nginx/domains/domain1.com/log Current vhost listing at: /usr/local/nginx/conf/conf.d/ Jun 21 13:10 798 ssl.conf Jun 21 13:10 1.1K demodomain.com.conf Jun 25 08:02 1.5K virtual.conf Jun 25 23:53 1.3K domain1.com.conf --------------------------------------------- The domain1 vhost file /usr/local/nginx/conf/conf.d/domain1.com.conf has Code: # redirect from non-www to www # uncomment, save file and restart Nginx to enable #server { # listen 80; # server_name domain1.com; # return 301 $scheme://www.domain1.com$request_uri; # } just uncomment and nginx restart Code: # redirect from non-www to www # uncomment, save file and restart Nginx to enable server { listen 80; server_name domain1.com; return 301 $scheme://www.domain1.com$request_uri; }
reverse it then Code: # redirect from non-www to www # uncomment, save file and restart Nginx to enable server { listen 80; server_name www.domain1.com; return 301 $scheme://domain1.com$request_uri; }
Glad to hear.. a good reliable and fast DNS provider makes all the difference - hence why I use DNSMadeEasy
Use CloudFlare DNS, no limit and it's FREE I'm using it for more than 1 month already without any problem.
I usually get through 1.5m per month, but have been able to decrease that as I've increased the TTL on the records now I'm happy with my hosting provider.
yeah I use more as centminmod.com uses DNSMadeEasy's DNS/IP failover for haproxy load balanced OpenVZ VPSes (can't edit sysctl.conf so work around via DME to keep hosting costs cheaper than switching all load balanced VPSes to KVM or Xen for sysctl.conf access )
Do not pause or your domain or else your website will be unreachable, just change the dns settings into this:
I have a similar issue. I want to redirect www to non-www via ssl. I got a Namecheap PositiveSSL cert that I'm not 100% certain if they cover both www and non-www. I got it issued for domain.com the problem is when I got to Domain Name Registration and Web Hosting | Domain.com it goes to Domain Name Registration and Web Hosting | Domain.com and not Domain Name Registration and Web Hosting | Domain.com Code: # redirect from www to non-www # uncomment, save file and restart Nginx to enable server { listen 80; server_name www.bvtot.com; return 301 $scheme://bvtot.com$request_uri; } server { listen 443 ssl spdy; server_name www.bvtot.com; ssl_certificate /usr/local/nginx/conf/ssl/bvtot.com/bvtot.com-unified.crt; ssl_certificate_key /usr/local/nginx/conf/ssl/bvtot.com/bvtot.com.key;
that's one you normally don't see accounted for but can be done via this entry within the SPDY SSL server context under root for Code: https://www.domain.com to Code: https://domain.com using 302 non-permanent redirect to test with first before using 301 permanent - test works for my sslspdy.com domain Code: ## redirect www to nowww if ($host = 'www.sslspdy.com' ) { return 302 https://$server_name$request_uri; } i.e. working Code: curl -I https://www.sslspdy.com/ HTTP/1.1 302 Moved Temporarily Server: nginx centminmod Date: Wed, 15 Oct 2014 20:47:23 GMT Content-Type: text/html Content-Length: 154 Connection: keep-alive Location: https://sslspdy.com/ Strict-Transport-Security: max-age=31536000 Alternate-Protocol: 443:npn-spdy/3 within SPDY SSL server context Code: server { listen 443 ssl spdy; SNIPPED REST root /home/nginx/domains/sslspdy.com/public; ## redirect www to nowww if ($host = 'www.sslspdy.com' ) { return 302 https://$server_name$request_uri; } location / {
Thank you George, You still left the 302 in your final code. It should be 301. I have been reading and trying all the solution I found via stackoverflow but none work. This is most recent one I tried Redirect non-www to www over SSL with Nginx - Server Fault In any case, your solution works but I always be interested if there is a more optimal solution or if we have any overheard if we do the checking for every connection.