Welcome to Centmin Mod Community
Become a Member

none to www

Discussion in 'Domains, DNS, Email & SSL Certificates' started by pamamolf, Oct 9, 2014.

  1. pamamolf

    pamamolf Well-Known Member

    2,820
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    5:15 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hi

    Please remind me how to redirect mydomain.com to www.mydomain.com

    Thanks :)
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,945
    6,914
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,411
    Local Time:
    1:15 AM
    Nginx 1.13.x
    MariaDB 5.5
    your default Nginx vhost generated yourdomain.conf has example of redirect for www to non-www that is commented out. Just reverse that for non-www to www and uncomment it
     
    • Like Like x 1
  3. sepulchre

    sepulchre Member

    90
    15
    8
    Dec 22, 2014
    Ratings:
    +15
    Local Time:
    4:15 PM
    How can I redirect from www to non-www?
     
  4. sepulchre

    sepulchre Member

    90
    15
    8
    Dec 22, 2014
    Ratings:
    +15
    Local Time:
    4:15 PM
    Anyone?

    My conf file looks like this (first lines of codes):


    Code:
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    #server {
    #            listen   80;
    #            server_name MyWebsite.com;
    #            return 301 $scheme://www.MyWebsite.com$request_uri;
    #       }
    
    server {
      server_name Mywebsite.com www.MyWebsite.com;
    Do I need to remove the www part and uncomment the above and comment the last line?
     
  5. eva2000

    eva2000 Administrator Staff Member

    30,945
    6,914
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,411
    Local Time:
    1:15 AM
    Nginx 1.13.x
    MariaDB 5.5
    as mentioned in 2nd post, just reverse the commented out example

    so something like
    Code:
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    server {
                listen   80;
                server_name www.MyWebsite.com;
                return 301 $scheme://MyWebsite.com$request_uri;
           }
    
    server {
      server_name MyWebsite.com;
     
    Last edited: Feb 11, 2015
    • Like Like x 1
  6. sepulchre

    sepulchre Member

    90
    15
    8
    Dec 22, 2014
    Ratings:
    +15
    Local Time:
    4:15 PM
    I get now this:

    upload_2015-2-10_22-55-35.png

    It says now I should do this: "You may now add content to the directory /usr/local/nginx/html."
    But my content is in /home/nginx/domains/MyWebsite.com/public
     
  7. eva2000

    eva2000 Administrator Staff Member

    30,945
    6,914
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,411
    Local Time:
    1:15 AM
    Nginx 1.13.x
    MariaDB 5.5
  8. sepulchre

    sepulchre Member

    90
    15
    8
    Dec 22, 2014
    Ratings:
    +15
    Local Time:
    4:15 PM
    I'm not sure. With "uname -n" I get the hostname I chose when I bought my VPS. So I didn't change the hostname.
    My registrar (namecheap) points to cloudflare for DNS and cloudflare has 2 Type A entries (localhost (127.0.0.1) and Mywebsite.com (MyVPS_IP)) and 1 Type CNAME entry.
    So I skipped all the things you describe in step 1 because I didn't feel the need to change my hostname.
    And then I did the last part of your step 1 and did this:
    Did I miss something?
    Just for your information, before the redirecting, I could entry to my website without a problem.
     
  9. eva2000

    eva2000 Administrator Staff Member

    30,945
    6,914
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,411
    Local Time:
    1:15 AM
    Nginx 1.13.x
    MariaDB 5.5
    did you check server_name in /usr/local/nginx/conf/conf.d/virtual.conf points to your server hostname output from uname -n ? if not, do that change and restart nginx server

    the uname -n should be different from your Mywebsite.com or www.Mywebsite.com names otherwise the default virtual.conf will take over your domain i.e. if uname -n is set to www.Mywebsite.com

    you'd have to show me your cloudflare dns setup/screenshot it too
     
  10. sepulchre

    sepulchre Member

    90
    15
    8
    Dec 22, 2014
    Ratings:
    +15
    Local Time:
    4:15 PM
    I checked that and it is correct. My virtual.conf file has the uname -n entry instead of localhost.

    Got that and it is different. My uname -n is called: server.MyWebsite.com

    Screenshot is in some seconds in your private message box.
     
  11. eva2000

    eva2000 Administrator Staff Member

    30,945
    6,914
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,411
    Local Time:
    1:15 AM
    Nginx 1.13.x
    MariaDB 5.5
    sorry instructions were wrong
    Code:
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    server {
                listen   80;
                server_name www.MyWebsite.com;
                return 301 $scheme://MyWebsite.com$request_uri;
           }
    
    server {
      server_name MyWebsite.com;
    remove 2nd server_name's www.