Discover Centmin Mod today
Register Now

Xenforo Nginx Rewrite for www

Discussion in 'Forum software usage' started by BoostN, Oct 15, 2014.

Tags:
  1. BoostN

    BoostN Active Member

    134
    27
    28
    Aug 19, 2014
    Ratings:
    +42
    Local Time:
    7:47 PM
    1.13.6
    10.0.34
    I have a Xenforo installation on a Digital Ocean server. I've used this forum for learning centminmod and nginx. So far I've been unable to get the rewrite to work for www. I've done some searching and reading but not seeing the answer...

    Right now it appears in my address bar as this:

    http://domain.com/forum/
    I want it to be:
    http://www.domain.com/forum/


    I made the change in RED in the config file located at:
    /usr/local/nginx/conf/conf.d for that domain

    Code:
    location /{
       rewrite ^/(.*) http://[COLOR=#ff0000]www.[/COLOR]$server_name/forum/ permanent;
      }
    
      location /forum/ {
                index index.php index.html index.htm;
                try_files $uri $uri/ /forum/index.php?$uri&$args;
    
    I ran nginx restart and still no noticeable change.
     
  2. rdan

    rdan Well-Known Member

    5,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    8:47 AM
    Mainline
    10.2
    Add on top:
    Code:
    server {
            listen 80;
            server_name phcorner.net;
            return 301 http://www.phcorner.net$request_uri;
    }
     
  3. BoostN

    BoostN Active Member

    134
    27
    28
    Aug 19, 2014
    Ratings:
    +42
    Local Time:
    7:47 PM
    1.13.6
    10.0.34
    That is how I have it now on top:


    Code:
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    #server {
    #            listen   80;
    #            server_name domain.com;
    #            return 301 $scheme://www.domain.com$request_uri;
    #       }
    
    server {
      server_name domain.com www.domain.com;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.com/log/access.log combined buffer=32k;
      error_log /home/nginx/domains/domain.com/log/error.log;
    
      root /home/nginx/domains/domain.com/public;
    
      location /{
       rewrite ^/(.*) http://www.$server_name/forum/ permanent;
      }
    
      location /forum/ {
                index index.php index.html index.htm;
                try_files $uri $uri/ /forum/index.php?$uri&$args;
    
            }
    
            location /forum/internal_data/ {
            internal;
            allow 127.0.0.1;
            deny all;
            }
    
            location /forum/library/ {
            internal;
            allow 127.0.0.1;
            deny all;
            }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
    }
    
     
  4. rdan

    rdan Well-Known Member

    5,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    8:47 AM
    Mainline
    10.2
    Un comment it.
     
  5. BoostN

    BoostN Active Member

    134
    27
    28
    Aug 19, 2014
    Ratings:
    +42
    Local Time:
    7:47 PM
    1.13.6
    10.0.34
    I feel stupid now.. thanks.

    I really thought the htaccess inside the forum root was the area to fix this. I've learned something new. Thanks again!
     
  6. rdan

    rdan Well-Known Member

    5,439
    1,398
    113
    May 25, 2014
    Ratings:
    +2,187
    Local Time:
    8:47 AM
    Mainline
    10.2
    htaccess doesn't work anymore on nginx so you can delete it.
     
  7. Afterward

    Afterward Member

    94
    29
    18
    Jul 20, 2014
    Ratings:
    +29
    Local Time:
    1:47 AM
    1.7.5
    5.5
    I wonder mine i think should be correct yet not showing the www at all
    Code:
    server {
      server_name site.com;
      return 301 https://www.site.com$request_uri;
    }
    # https SSL SPDY vhost
    
    Anything wrong?
     
  8. eva2000

    eva2000 Administrator Staff Member

    53,531
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    10:47 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    should work... did you just uncomment it or added it ? you'd need to restart nginx for vhost changes to take affect
     
  9. Afterward

    Afterward Member

    94
    29
    18
    Jul 20, 2014
    Ratings:
    +29
    Local Time:
    1:47 AM
    1.7.5
    5.5
    added it and yea i restarted nginx but didin't work somehow, idk why.
     
  10. Afterward

    Afterward Member

    94
    29
    18
    Jul 20, 2014
    Ratings:
    +29
    Local Time:
    1:47 AM
    1.7.5
    5.5
    www show in firefox but not in chrome o_O
     
  11. Andy

    Andy Active Member

    540
    89
    28
    Aug 6, 2014
    Ratings:
    +132
    Local Time:
    7:47 PM
  12. eva2000

    eva2000 Administrator Staff Member

    53,531
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    10:47 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    sounds like a Chrome problem then provided you have correct redirect
     
  13. Afterward

    Afterward Member

    94
    29
    18
    Jul 20, 2014
    Ratings:
    +29
    Local Time:
    1:47 AM
    1.7.5
    5.5
    What confuses me that i can see the www in other sites in chrome but not in mine? dis chrome confuses me alot
     
  14. Matt

    Matt Well-Known Member

    926
    414
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +669
    Local Time:
    1:47 AM
    1.5.15
    MariaDB 10.2
    I've seen it where Chrome has cached it.
     
  15. eva2000

    eva2000 Administrator Staff Member

    53,531
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    10:47 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    ah in that case folks try accessing your domain via Chrome in incognito mode first
     
  16. Andy

    Andy Active Member

    540
    89
    28
    Aug 6, 2014
    Ratings:
    +132
    Local Time:
    7:47 PM
    Same. I don't know if there is a problem with Chrome browser 64bit on Mac or something.