Organizational Research By

Surprising Reserch Topic

WordPress multisites subdirectories on nginx and not root folder not working properly


I have a WordPress multisites with nginx installed like this:

http://demo.example.com/wordpress/
http://demo.example.com/wordpress/wp-admin/
http://demo.example.com/wordpress/subsite1/
http://demo.example.com/wordpress/subsite2/

Accessing my main site @ http://demo.example.com/wordpress/ is working, and the wp-admin is working too.

When accessing a sub-site @ http://demo.example.com/wordpress/subsite1/ for example, the site is loading but every assets is giving a 404 errors due to a bad URL : http://demo.example.com/wordpress/subsite1/wp-content/themes/impala/js/bootstrap.min.js?ver=3.0.2 
** instead of** http://demo.example.com/wordpress/wp-content/themes/impala/js/bootstrap.min.js?ver=3.0.2

It's always putting the name of the subsite when trying to load assets in a "subsite" site.

Here's my config, I'v tried tons of config that I found around but this is the closest thing that's almost working for me, I don't know why :(

map $uri $blogname{
        ~^(?/[^/]+/)files/(.*)        $blogpath ;
}

map $http_host $blogid {
        default -999;
        include /var/www/demo.example.com/htdocs/wordpress/wp-content/uploads/nginx-helper/map.conf;
}

server {
        listen 80;
        listen [::]:80;
        server_name demo.example.com;
        root /var/www/demo.example.com/htdocs/wordpress;
        index index.php index.html index.htm;

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

        # Directives to send expires headers and turn off 404 error logging.
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires 24h;
                log_not_found off;
        }

        # Directives to send expires headers and turn off 404 error logging.
        location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|$
                access_log off; log_not_found off; expires max;
        }

        #location ~ ^/[_0-9a-zA-Z-]+/files/(.*)$ {
        #       try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
        #       access_log off; log_not_found off; expires max;
        #}

        location ~ ^(/[^/]+/)?files/(?.+) {
                try_files /wp-content/blogs.dir/$blogid/files/$rt_file /wp-includes/ms-files.php?file=$rt_file ;
                access_log off; log_not_found off; expires max;
        }

        #avoid php readfile()
        location ^~ /blogs.dir {
                internal;
                alias /var/www/demo.example.com/htdocs/wordpress/wp-content/blogs.dir ;
                access_log off; log_not_found off;  expires max;
        }


        # Rewrite multisite '.../wp-.*' and '.../*.php'.
        if (!-e $request_filename) {
                rewrite /wp-admin$ $scheme://$host$uri/ permanent;
                rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
                rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
        }


}

Am I missing something? I've read that MU in subdirectories can be a pain, but I don't know what to do right now :/

asked Jun 9, 2015 in LINUX by rajesh
0 votes
55 views



Related Hot Questions



Government Jobs Opening


...