简体   繁体   中英

nginx load wordpress from a subdirectory

I followed a guide from here to install wordpress on my ubuntu server. Upon entering the url http://mydomain.com loads me the front page.

     server {
    listen 80 default_server;

    root /var/www/wordpress;
    index index.php index.html index.htm;

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

    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;
    }

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

工作wordpress

I want to load wordpress from my subdomain ie, http://mydomain.com/wordpress . I went on to modify the location but it can't load properly (it still looks for files under http://mydomain.com ).

    root /var/www;
    index index.php index.html index.htm;

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

or

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

WordPress失败

How do I fix this? thanks

Your wordpress looking for his files in root directory. / So you need to tell him, to search his files in the right directory. /wordpress/ There are two ways. Better: to change the path using wordpress config file for rewriting resources path

from

/css/*, /*    etc

to

/wordpress/css/*, /wordpress/*   and so on. 

Worst: to redirect your wordpress resources to root directory. Something like this:

  location ~ ^/images/(.*)$ {
    try_files $uri /wordpress/images/$uri =404;
    access_log off;
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM