NginX Configuration - Rewrite Issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • David Karol
    Member
    • Jan 2011
    • 72
    • 5.5.x

    [Forum] NginX Configuration - Rewrite Issues

    I'm currently using the following nginx rewrite rules for my CMS, Blog, and Forums, which I've found posted in these forums:

    Code:
    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;
    I can't load actual threads, posts, and blogs. After making some changes, I'm able to load the members list, along with the list of threads (each forum.) Here's my config file for the virtual host, and then that for nginx itself (slightly modified):
    Code:
    server {
        listen   80;
        server_name x x x x;
        access_log /home/x/www/x/logs/access.log;
        error_log /home/x/www/x/logs/error.log;
            root   /home/x/www/x/public_html/;
    
        location / {
            index index.php  index.html index.htm;
            rewrite ^/live/threads/([0-9]+)  /showthread.php?t=$1&page=$2;
            rewrite ^/live/members/([0-9]+) /member.php?u=$1;
    #       rewrite ^/live/forums/([0-9]+)(?:/?$|(?:-[^/]+))(?:/?$|(?:/page([0-9]+)?)) /forumdisplay.php?$
            rewrite ^/live/forums/([0-9]+) /forumdisplay.php?f=$1;
            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=$$
            rewrite ^/list/([^/]*/)([0-9]+) /list.php?r=$1$2;
            rewrite ^/content/(.*) /content.php?r=$1;
       }
    
    
       }
    
    
        # Pass PHP scripts on to PHP-FPM
        location ~* \.php$ {
            try_files       $uri /index.php;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    }
    Code:
    user www-data;
    worker_processes 4;
    pid /var/run/nginx.pid;
    
    
    events {
            worker_connections 768;
            # multi_accept on;
    }
    
    
    http {
    
    
            ##
            # Basic Settings
            ##
    
    
            sendfile on;
            tcp_nopush on;
            tcp_nodelay on;
            keepalive_timeout 65;
            types_hash_max_size 2048;
            # server_tokens off;
    
    
            # server_names_hash_bucket_size 64;
            # server_name_in_redirect off;
    
    
            include /etc/nginx/mime.types;
            default_type application/octet-stream;
    
    
            ##
            # Logging Settings
            ##
    
    
            access_log /var/log/nginx/access.log;
            error_log /var/log/nginx/error.log;
    
    
            ##
            # Gzip Settings
            ##
    
    
            gzip on;
            gzip_disable "msie6";
            gzip_disable "msie6";
    
    
            # gzip_vary on;
            # gzip_proxied any;
            # gzip_comp_level 6;
            # gzip_buffers 16 8k;
            # gzip_http_version 1.1;
            # gzip_types text/plain text/css application/json application/x-javascript text/xml applicati$
    
    
            ##
            # If HTTPS, then set a variable so it can be passed along.
            ##
    
    
            map $scheme $server_https {
                    default off;
                    https on;
            }
    
    
            ##
            # Virtual Host Configs
            ##
    
    
            include /etc/nginx/conf.d/*.conf;
            include /etc/nginx/sites-enabled/*;
    }
    Any ideas?

    Thanks,

    dk
    Last edited by David Karol; Sat 15 Sep '18, 12:32am.
  • David Karol
    Member
    • Jan 2011
    • 72
    • 5.5.x

    #2
    Apache Rewrites

    Here is the rewriting section I was using on Apache from first the root folder, than the forum and blog stub directories:

    Root:
    Code:
    RewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    
    
    RewriteRule ^.*$ - [NC,L]
    
    
    # Forum
    RewriteRule ^threads/.* showthread.php [QSA]
    RewriteRule ^forums/.* forumdisplay.php [QSA]
    RewriteRule ^members/.* member.php [QSA]
    RewriteRule ^blogs/.* blog.php [QSA]
    RewriteRule ^entries/.* entry.php [QSA]
    
    
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    
    
    RewriteRule ^.*$ - [NC,L]
    
    
    # MVC
    RewriteCond %{REQUEST_FILENAME} !\.php$
    RewriteRule ^(?:(.*?)(?:/|$))(.*|$)$ $1.php?r=$2 [QSA]
    Forum (/live)
    Code:
    RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    
    
    RewriteRule ^.*$ - [NC,L]
    
    
    # Forum
    RewriteRule ^threads/.* showthread.php [QSA]
    RewriteRule ^forums/.* forumdisplay.php [QSA]
    RewriteRule ^members/.* member.php [QSA]
    Blog (/blog)
    Code:
    RewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    
    
    RewriteRule ^.*$ - [NC,L]
    
    
    RewriteRule ^blogs/.* blog.php [QSA]
    RewriteRule ^entries/.* entry.php [QSA]

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...