Join the community today
Register Now

Problem with domain resolve

Discussion in 'Virtual Private Server (VPS) hosting' started by pamamolf, Jun 25, 2014.

  1. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    i do both www A record and nginx redirect as it won't work if you don't resolve www via DNS

     
  2. pamamolf

    pamamolf Premium Member Premium Member

    4,069
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    7:20 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    How can i do this on nginx?
     
  3. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    .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;
           }
     
  4. pamamolf

    pamamolf Premium Member Premium Member

    4,069
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    7:20 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    But this is not what i want:

    redirect from non-www to www

    i need this:

    redirect from www to non-www
     
  5. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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;
           }
     
  6. pamamolf

    pamamolf Premium Member Premium Member

    4,069
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    7:20 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Problem solved 100% with namecheap :)

    I hope Godaddy to fix the problem soon.....
     
  7. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Glad to hear.. a good reliable and fast DNS provider makes all the difference - hence why I use DNSMadeEasy ;)
     
  8. pamamolf

    pamamolf Premium Member Premium Member

    4,069
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    7:20 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    I know that they are the best !

    This is what i hate on them :)

    5 Million Queries per Month * Limit
     
  9. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Business plan = 10m queries/month

    I'm only using 2-3m out of 10m per month heh
     
  10. rdan

    rdan Well-Known Member

    5,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    12:20 PM
    Mainline
    10.2
    Use CloudFlare DNS, no limit and it's FREE ;)
    I'm using it for more than 1 month already without any problem.
     
  11. dorobo

    dorobo Active Member

    420
    104
    43
    Jun 6, 2014
    Ratings:
    +162
    Local Time:
    12:20 PM
    latest
    latest
    You're not using the CDN, just the DNS?

    So is your setting like this?

    [​IMG]
     
  12. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yeah you can just use Cloudflare for DNS and turn off CDN :)
     
  13. pamamolf

    pamamolf Premium Member Premium Member

    4,069
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    7:20 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok thanks :)
     
  14. Matt

    Matt Well-Known Member

    926
    414
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +669
    Local Time:
    5:20 AM
    1.5.15
    MariaDB 10.2
    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.
     
  15. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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 :) )
     
  16. rdan

    rdan Well-Known Member

    5,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    12:20 PM
    Mainline
    10.2
    Do not pause or your domain or else your website will be unreachable, just change the dns settings into this:
    upload_2014-6-27_22-41-30.png
     
  17. Andy

    Andy Active Member

    540
    89
    28
    Aug 6, 2014
    Ratings:
    +132
    Local Time:
    11:20 PM
    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;
     
  18. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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 / {
     
  19. Andy

    Andy Active Member

    540
    89
    28
    Aug 6, 2014
    Ratings:
    +132
    Local Time:
    11:20 PM
    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.
     
  20. eva2000

    eva2000 Administrator Staff Member

    53,535
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    2:20 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yeah left 302 so folks can test it first before changing it to 301