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 Active Member

    118
    26
    28
    Aug 19, 2014
    Ratings:
    +37
    Local Time:
    7:46 AM
    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 Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    8:46 PM
    Mainline
    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 Active Member

    118
    26
    28
    Aug 19, 2014
    Ratings:
    +37
    Local Time:
    7:46 AM
    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 Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    8:46 PM
    Mainline
    10.2
    Un comment it.
     
    • Like Like x 2
  5. BoostN

    BoostN Active Member

    118
    26
    28
    Aug 19, 2014
    Ratings:
    +37
    Local Time:
    7:46 AM
    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 Premium Member Premium Member

    4,255
    1,034
    113
    May 25, 2014
    Ratings:
    +1,486
    Local Time:
    8:46 PM
    Mainline
    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:
    1:46 PM
    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

    36,041
    7,907
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,189
    Local Time:
    10:46 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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:46 PM
    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:46 PM
    1.7.5
    5.5
    www show in firefox but not in chrome o_O
     
  11. Andy

    Andy Premium Member Premium Member

    419
    60
    28
    Aug 6, 2014
    Ratings:
    +83
    Local Time:
    8:46 AM
  12. eva2000

    eva2000 Administrator Staff Member

    36,041
    7,907
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,189
    Local Time:
    10:46 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    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:
    1:46 PM
    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

    765
    343
    63
    May 25, 2014
    Sheffield, UK
    Ratings:
    +512
    Local Time:
    1:46 PM
    1.7.1
    MariaDB 10
    I've seen it where Chrome has cached it.
     
  15. eva2000

    eva2000 Administrator Staff Member

    36,041
    7,907
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,189
    Local Time:
    10:46 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    ah in that case folks try accessing your domain via Chrome in incognito mode first
     
  16. Andy

    Andy Premium Member Premium Member

    419
    60
    28
    Aug 6, 2014
    Ratings:
    +83
    Local Time:
    8:46 AM
    Same. I don't know if there is a problem with Chrome browser 64bit on Mac or something.
     
..