Adding Vbulletin Nginx Rewrite rules

Cant seem to get this right. I used VladGh's LEMP script to perform the install which produces the following nginx.conf:

user www-data;
worker_processes     4;
error_log  /var/log/nginx/nginx.log info;
pid        /var/run/nginx.pid;

events {
  worker_connections  1024;
  multi_accept on;
}

http {
  include           fastcgi.conf;
  include           mime.types;
  default_type      application/octet-stream;
  set_real_ip_from  127.0.0.1;
  real_ip_header    X-Forwarded-For;

  ## Proxy
  proxy_redirect          off;
  proxy_set_header        Host  $host;
  proxy_set_header        X-Real-IP $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  client_max_body_size    10m;
  client_body_buffer_size 128k;
  proxy_connect_timeout   90;
  proxy_send_timeout      90;
  proxy_read_timeout      90;
  proxy_buffers           32 4k;

  ## Compression
  gzip             on;
  gzip_types       text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  gzip_disable     "MSIE [1-6]\.(?!.*SV1)";

  ### TCP options
  tcp_nodelay         on;
  tcp_nopush          on;
  keepalive_timeout   65;
  sendfile            on;

  server {

    server_name _ "";

    access_log  /var/log/nginx/$host.access.log;
    error_log   /var/log/nginx/error.log;

    root    /var/www;
    index   index.php index.html;

    ## Block bad bots
    if ($http_user_agent ~* (HTTrack|HTMLParser|libcurl|discobot|Exabot|Casper|kmccrew|plaNETWORK|RPT-HTTPClient)) {
      return 444;
    }

    ## Block certain Referers (case insensitive)
    if ($http_referer ~* (sex|vigra|viagra) ) {
      return 444;
    }

    ## Deny dot files:
    location ~ /\. {
      deny all;
    }

    ## Favicon Not Found
    location = /favicon.ico {
      access_log off;
      log_not_found off;
    }

    ## Robots.txt Not Found
    location = /robots.txt { 
      access_log off; 
      log_not_found off; 
    }

    location / {
      try_files $uri $uri/ index.php;
    }  

    location ~ \.php$ {
      include /etc/nginx/fastcgi.conf;
      fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    ### NginX Status
    location /nginx_status {
    stub_status on;
      access_log   off; 
    }

    ### FPM Status
    location ~ ^/(status|ping)$ {
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      access_log      off;
    }

  }

}

I just need to add the following from my previous apache setup:

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteRule ^includes/(.*) index.php
RewriteRule ^vb/(.*) index.php
RewriteRule ^packages/(.*) index.php
RewriteRule ^threads/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) showthread.php?t=$1&page=$2&%{QUERY_STRING}
RewriteRule ^members/([0-9]+) member.php?u=$1&%{QUERY_STRING}
RewriteRule ^forums/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) forumdisplay.php?f=$1&page=$2&{QUERY_STRING}
RewriteRule ^blogs/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) blog.php?u=$1&page=$2&%{QUERY_STRING}
RewriteRule ^entries/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) entry.php?b=$1&page=$2&%{QUERY_STRING}
RewriteRule ^list/([^/]*/)([0-9]+) list.php?r=$1$2&{QUERY_STRING}
RewriteRule ^content/(.*) content.php?r=$1&%{QUERY_STRING}
RewriteRule ^widget/config/([0-9]+) widget.php?r=config/$1&%{QUERY_STRING}

Thanks.

2 Replies

Apache's Rewrite configuration is not directly compatible with other web servers. You'll have to translate the rules into something nginx can understand, either line-for-line using rewrite or by figuring out what the rules are trying to do and writing an nginx configuration to do it with minimal rewriting. Both are formidable tasks, and I would consider being Apache-specific to be a vBulletin bug.

Found this over at vbulletin.com

rewrite ^/threads/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) /showthread.php?t=$1&page=$2;
rewrite ^/members/([0-9]+) /member.php?u=$1;
rewrite ^/forums/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) /forumdisplay.php?f=$1&page=$2;
rewrite ^/blogs/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) /blog.php?u=$1&page=$2;
rewrite ^/entries/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) /entry.php?b=$1&page=$2;
rewrite ^/list/([^/]*/)([0-9]+) /list.php?r=$1$2;
rewrite ^/content/(.*) /content.php?r=$1;

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct