nginx从子目录加载wordpress

时间:2014-06-27 06:45:36

标签: php wordpress nginx

我按照here的指南在我的ubuntu服务器上安装wordpress。输入网址http://mydomain.com后,我会在首页加载。

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

Working wordpress

我想从我的子域加载wordpress,即http://mydomain.com/wordpress。我继续修改位置,但无法正确加载(它仍在http://mydomain.com下查找文件)。

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

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

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

Wordpress fails

我该如何解决这个问题?感谢

1 个答案:

答案 0 :(得分:0)

你的wordpress在根目录中查找他的文件。 / 所以你需要告诉他,在正确的目录中搜索他的文件。 / WordPress的/ 有两种方法。 更好:使用wordpress配置文件更改路径以重写资源路径

来自

/css/*, /*    etc

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

最糟糕的是:将wordpress资源重定向到根目录。像这样:

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