Nginx config for wordpress in subfolder with rewrites for main folder

sip nginx-forum at
Wed Apr 15 16:58:20 UTC 2015

I have a vbulletin site in root and a wordpress blog in /blog/

the root nginx rewrites all work as they should utilising the dbseo plugin
for vbulletin to make search engine friendly urls

if i turn on permalinks in wordpress i get a 404 error no matter what i

Could anyone advise what the change should be to be able to use a different
set of rewrite rules in just the blog folder.

I am hoping to have other wordpress installs for different purposes so this
will hopefully explain for the future also.

Current domain.conf for nginx

server {
        listen 80;
        #listen [::]:80 default ipv6only=on;

        root /home/username/domains/;
        access_log /home/username/domains/;
        error_log /home/username/domains/;

        index index.php index.html index.htm;
        error_page 404 /404.html;

        location / {
            try_files $uri $uri/ /dbseo.php;

        location ~ ^((?!dbseo).)*\.php$
                rewrite ^/(.*)$ /dbseo.php last;

        # Pass PHP scripts to PHP-FPM
        location ~ \.php$ {
            try_files $uri =403;
            fastcgi_split_path_info ^(/blog)(/.*)$;
            fastcgi_pass unix:/var/run/php5-fpm-username.sock;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME 

        # Enable browser cache for CSS / JS
        location ~* \.(?:css|js)$ {
            expires 30d;
            add_header Pragma "public";
            add_header Cache-Control "public";
            add_header Vary "Accept-Encoding";

        # Enable browser cache for static files
        location ~*
            expires 60d;
            add_header Pragma "public";
            add_header Cache-Control "public";

        # Deny access to hidden files
        location ~ (^|/)\. {
            deny all;

        # Prevent logging of favicon and robot request errors
        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt  { log_not_found off; access_log off; }

I have tried a load of different options to get this to work.

I have posted these on stackoverflow which is possibly simpler than posting
again here. 
thats here

Any help w2ould be most appreciated.

I think i just need the basics of how to ignore / include certain rules for
certain pages.

how do i make /blog/ only use its own rules and ignore everything else.?

Posted at Nginx Forum:,258060,258060#msg-258060

More information about the nginx mailing list