How do I move a CMS installation from root to subdirectory (nginx)

0

0

I've inadvertently installed Wordpress into the root of my Ubuntu nginx server. How do I move this installation from root to a subdirectory called /blog? ex. mysite.com/blog

What I have now:

server {
listen 80;
server_name mysite.com;
root /srv/www/wordpress;
index index.php index.html index.htm;

include conf.d/wp/restrictions.conf;

# Additional rules go here.

include conf.d/wp/wordpress.conf;
}

Below is the conf.d/wp/wordpress.conf

# WordPress single blog rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule

location / {
        index index.html index.htm index.php;
}

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

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# 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|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
}

# Uncomment the line below for the W3 total caching plugin (if used).
#include conf.d/wp/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
        # Zero-day exploit defense.
        # http://forum.nginx.org/read.php?2,88845,page=3
        # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine.  And then cross your fingers that you won't get hacked.
        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#       fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
}

Despite adding:

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

FYI Wordpress is still located in /srv/www/wordpress

...it still isn't working, which makes me wonder if I actually understand what I'm doing!

Any help is appreciated. Thank you.

Atlas2k

Posted 2015-07-28T14:01:57.737

Reputation: 51

Do I have to make any changes to the database since Wordpress has already been installed? – Atlas2k – 2015-07-28T14:02:39.667

Answers

0

Fixed this by moving /srv/www/wordpress to a subdirectory. The final URI is: /srv/www/html/blog with the Wordpress files in /srv/www/html/blog

The server block then will have this instead: root /srv/www/html;

# Redirects users from root to /blog
location = / {
    return 301 http://example.com/blog;
}

location /blog {
#       index index.html index.htm index.php;
        try_files $uri $uri/ /blog/index.php?$args;
}

Atlas2k

Posted 2015-07-28T14:01:57.737

Reputation: 51