Get the most out of your Centmin Mod LEMP stack
Become a Member

Xenforo Nginx Rewrite for www

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

Tags:
  1. BoostN

    BoostN Member

    93
    18
    8
    Aug 19, 2014
    Ratings:
    +22
    Local Time:
    9:57 PM
    1.11.1
    10.0.28
    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. RoldanLT

    RoldanLT Well-Known Member

    3,975
    965
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,329
    Local Time:
    11:57 AM
    1.11
    10.2
    Add on top:
    Code:
    server {
            listen 80;
            server_name phcorner.net;
            return 301 http://www.phcorner.net$request_uri;
    }
     
    • Like Like x 1
  3. BoostN

    BoostN Member

    93
    18
    8
    Aug 19, 2014
    Ratings:
    +22
    Local Time:
    9:57 PM
    1.11.1
    10.0.28
    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. RoldanLT

    RoldanLT Well-Known Member

    3,975
    965
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,329
    Local Time:
    11:57 AM
    1.11
    10.2
    Un comment it.
     
    • Like Like x 2
  5. BoostN

    BoostN Member

    93
    18
    8
    Aug 19, 2014
    Ratings:
    +22
    Local Time:
    9:57 PM
    1.11.1
    10.0.28
    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. RoldanLT

    RoldanLT Well-Known Member

    3,975
    965
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,329
    Local Time:
    11:57 AM
    1.11
    10.2
    htaccess doesn't work anymore on nginx so you can delete it.
     
    • Like Like x 2
  7. Afterward

    Afterward Member

    94
    29
    18
    Jul 20, 2014
    Ratings:
    +29
    Local Time:
    4:57 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

    30,839
    6,903
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,393
    Local Time:
    1:57 PM
    Nginx 1.13.x
    MariaDB 5.5
    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:
    4:57 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:
    4:57 AM
    1.7.5
    5.5
    www show in firefox but not in chrome o_O
     
  11. Andy

    Andy Active Member

    333
    48
    28
    Aug 6, 2014
    Ratings:
    +57
    Local Time:
    10:57 PM
  12. eva2000

    eva2000 Administrator Staff Member

    30,839
    6,903
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,393
    Local Time:
    1:57 PM
    Nginx 1.13.x
    MariaDB 5.5
    sounds like a Chrome problem then provided you have correct redirect
     
    • Like Like x 1
  13. Afterward

    Afterward Member

    94
    29
    18
    Jul 20, 2014
    Ratings:
    +29
    Local Time:
    4:57 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 Moderator Staff Member

    697
    322
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +449
    Local Time:
    3:57 AM
    1.7.1
    MariaDB 10
    I've seen it where Chrome has cached it.
     
  15. eva2000

    eva2000 Administrator Staff Member

    30,839
    6,903
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,393
    Local Time:
    1:57 PM
    Nginx 1.13.x
    MariaDB 5.5
    ah in that case folks try accessing your domain via Chrome in incognito mode first
     
  16. Andy

    Andy Active Member

    333
    48
    28
    Aug 6, 2014
    Ratings:
    +57
    Local Time:
    10:57 PM
    Same. I don't know if there is a problem with Chrome browser 64bit on Mac or something.