Nginx - Wordpress in a Sub-directory

June 26, 2015 7.1k views
Nginx Ubuntu

I am running wordpress in a sub-directory /wordpress, I want it to be served at root. I cannot change the application root to /wordpress, because i have a core php application at root, which runs as example.com/some_file.php . My configuration file run wordpress homepage and other pages fine, but wp-admin pages are broken, also any images put in wp-content folder are broken when called from within the theme. My configuration file for rewrites is:


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

location /wordpress {
    index index.php;
    try_files $uri $uri/ /wordpress/index.php?$args;
}
location ~ \.php$ {
  try_files $uri =404;
  include fastcgi_params;
  fastcgi_pass php;
}

code

The link to my site is this and link to wp-admin is here

1 Answer

With this Nginx configuration, I was able to achieve this on Ubuntu 14.04.

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /var/www/html;
        # server_name your_domain.com;

        location / {
                try_files $uri /wordpress/index.php?q=$uri&$args;
        }

        location /wordpress {
                index index.php index.html index.htm;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}
Have another answer? Share your knowledge.