Join the community today
Become a Member

none to www

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

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,069
    427
    83
    May 31, 2014
    Ratings:
    +832
    Local Time:
    2:15 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Hi


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

    Thanks :)
     
  2. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    9:15 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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
     
  3. sepulchre

    sepulchre Member

    167
    22
    18
    Dec 22, 2014
    Ratings:
    +28
    Local Time:
    1:15 AM
    How can I redirect from www to non-www?
     
  4. sepulchre

    sepulchre Member

    167
    22
    18
    Dec 22, 2014
    Ratings:
    +28
    Local Time:
    1:15 AM
    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

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    9:15 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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
  6. sepulchre

    sepulchre Member

    167
    22
    18
    Dec 22, 2014
    Ratings:
    +28
    Local Time:
    1:15 AM
    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

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    9:15 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  8. sepulchre

    sepulchre Member

    167
    22
    18
    Dec 22, 2014
    Ratings:
    +28
    Local Time:
    1:15 AM
    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

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    9:15 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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

    167
    22
    18
    Dec 22, 2014
    Ratings:
    +28
    Local Time:
    1:15 AM
    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

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    9:15 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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.