简体   繁体   English

nginx从子目录加载wordpress

[英]nginx load wordpress from a subdirectory

I followed a guide from here to install wordpress on my ubuntu server. 我按照这里的指南在我的ubuntu服务器上安装了wordpress。 Upon entering the url http://mydomain.com loads me the front page. 输入网址后, 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;
    }
    }

工作wordpress

I want to load wordpress from my subdomain ie, http://mydomain.com/wordpress . 我想从我的子域http://mydomain.com/wordpress加载wordpress。 I went on to modify the location but it can't load properly (it still looks for files under http://mydomain.com ). 我继续修改位置,但是无法正确加载(它仍然在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. 您的wordpress在根目录中查找他的文件。 / So you need to tell him, to search his files in the right directory. /所以您需要告诉他,在正确的目录中搜索他的文件。 /wordpress/ There are two ways. / wordpress /有两种方法。 Better: to change the path using wordpress config file for rewriting resources path 更好:使用wordpress配置文件更改路径以重写资源路径

from

/css/*, /*    etc

to

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

Worst: to redirect your wordpress resources to root directory. 最差:将您的wordpress资源重定向到根目录。 Something like this: 像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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