Trong tut này mình sẽ hướng dẫn các bạn cách cấu hình file vhost cho vbb trên nginx để rewrite url khi dùng VBSeo.

1. Code đặt trong thư mục forum

Mã:
server {
#        listen  80;
            listen  80 default_server;
            server_name localhost;
            root  html;

        access_log              /var/log/nginx/localhost.access.log    main buffer=32k;
        error_log              /var/log/nginx/localhost.error.log      error;

# limit_conn limit_per_ip 16;
# ssi  on;

            location / {

#              Enables directory listings when index file not found
                autoindex  on;

#              Shows file listing times as local time
#              autoindex_localtime on;

#              Enable for vBulletin usage WITHOUT vbSEO installed
#              try_files              $uri $uri/ /index.php;

            }



location /forum/ {
rewrite ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;

try_files $uri $uri/ /forum/vbseo.php?$args;
}

        location /forum/includes {
        allow 127.0.0.1;
        deny all;
        }

        location /forum/packages {
        allow 127.0.0.1;
        deny all;
        }

        location /forum/vb {
        allow 127.0.0.1;
        deny all;
        }

        location /forum/admincp {
        include /usr/local/nginx/conf/php.conf;
        #auth_basic "Private";
        #auth_basic_user_file /usr/local/nginx/conf/htpasswd;
        }

location /forum/vbseo/(includes|resources/html|resources/xml)/ {
        allow      127.0.0.1;
        deny      all;
}

location ~ /forum/(.*\.php)$ {
rewrite ^/forum/(.*)$ /forum/vbseo.php last;
}

        }
2. Code đặt tại public_html

Mã:
server {
#        listen  80;
            listen  80 default_server;
            server_name localhost;
            root  html;

        access_log              /var/log/nginx/localhost.access.log    main buffer=32k;
        error_log              /var/log/nginx/localhost.error.log      error;

# limit_conn limit_per_ip 16;
# ssi  on;

            location / {

#              Enables directory listings when index file not found
                autoindex  on;

#              Shows file listing times as local time
#              autoindex_localtime on;

#              Enable for vBulletin usage WITHOUT vbSEO installed
#              try_files              $uri $uri/ /index.php;

            }


location / {
rewrite ^/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ /vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;

try_files $uri $uri/ /vbseo.php?$args;
}

        location /includes {
        allow 127.0.0.1;
        deny all;
        }

        location /packages {
        allow 127.0.0.1;
        deny all;
        }

        location /vb {
        allow 127.0.0.1;
        deny all;
        }

        location /admincp {
        include /usr/local/nginx/conf/php.conf;
        #auth_basic "Private";
        #auth_basic_user_file /usr/local/nginx/conf/htpasswd;
        }

location /vbseo/(includes|resources/html|resources/xml)/ {
        allow      127.0.0.1;
        deny      all;
}

location ~ /(.*\.php)$ {
rewrite ^/(.*)$ /vbseo.php last;
}

        }


3. Trường hợp bị lỗi khi dùng 2 rule trên thì dùng rule sau:

    rewrite ^/((urllist|sitemap_).*.(xml|txt)(.gz)?)$ /vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
if ($uri !~ "(admincp/|modcp/|cron|vbseo_sitemap|api.php)"){
    set $rule_1 1$rule_1;
}
if ($rule_1 = "1"){
    rewrite ^/((archive/)?(.*.php(/.*)?))$ /vbseo.php last;
}
if (!-f $request_filename){
    set $rule_2 1$rule_2;
}
if (!-d $request_filename){
    set $rule_2 2$rule_2;
}
if ($request_filename !~ "/(admincp|modcp|clientscript|cpstyles|images)/"){
    set $rule_2 3$rule_2;
}
if ($rule_2 = "321"){
    rewrite ^/(.+)$ /vbseo.php last;
}


Lưu ý trên đây là khung sườn các bạn có thể tùy biến thêm nếu muốn.

Đăng nhận xét Blogger

 
Top