Nginx-子目录中的wordpress,应该传递什么数据? [英] Nginx - wordpress in a subdirectory, what data should be passed?

查看:62
本文介绍了Nginx-子目录中的wordpress,应该传递什么数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多不同的事情.我现在要说的是:

I've tried so many different things. The point I'm at right now is this:

location ^~ /wordpress {
    alias /var/www/example.com/wordpress;
    index index.php index.html index.htm;
    try_files $uri $uri/ /wordpress/index.php;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(/wordpress)(/.*)$;
        fastcgi_param SCRIPT_FILENAME /var/www/example.com/wordpress/index.php;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

目前,据我所知,所有资源(图像等)都已正确加载.并且http://www.example.com/wordpress加载wordpress,但是页面显示找不到页面". (虽然为此使用了Wordpress).如果我尝试任何发布网址,都会得到相同的结果,找不到页面".因此,我知道问题在于wordpress无法获取有关路径或其他内容的数据.另一个潜在的问题是,如果我运行example.com/wp-admin.php,它将仍然运行index.php.

Right now, all resources as far as I can tell (images, etc) are loading correctly. And http://www.example.com/wordpress loads wordpress, but a page that says "page not found". (Wordpress is in use for this though). If I try any post urls I get the same result, "page not found". So I know the problem is that wordpress isn't obtaining the data about the path or something. Another potential problem is that if I run example.com/wp-admin.php then it will still run index.php.

需要传递什么数据?这里可能出什么问题了?

What data needs to be passed? What may be going wrong here?

推荐答案

由于您的位置别名结尾匹配,因此您应该只使用root.另外,不是一切都是通过wordpress afaik上的index.php路由的.另外,除非您知道需要路径信息,否则可能不需要.我想您想要类似的东西:

Since your location alias end match, you should just use root. Also, not everything is routed through index.php on wordpress afaik. Also, unless you know you need path info, you probably dont. I think you want something like:

location @wp {
  rewrite ^/wordpress(.*) /wordpress/index.php?q=$1;
}

location ^~ /wordpress {
    root /var/www/example.com;
    index index.php index.html index.htm;
    try_files $uri $uri/ @wp;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass 127.0.0.1:9000;
    }
}

或者如果您确实需要路径信息(URL看起来像/wordpress/index.php/foo/bar):

or if you really do need path info (urls look like /wordpress/index.php/foo/bar):

location ^~ /wordpress {
    root /var/www/example.com;
    index index.php index.html index.htm;
    try_files $uri $uri/ /wordpress/index.php;

    location ~ \.php {
        fastcgi_split_path_info ^(.*\.php)(.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_pass 127.0.0.1:9000;
    }
}

更新了第一台服务器{},以从uri中剥离初始/wordpress并将余数作为q参数传递

Updated first server{} to strip initial /wordpress from uri and pass remainder as q param

命名位置仅在服务器级别有效

Named locations are only valid at server level

这篇关于Nginx-子目录中的wordpress,应该传递什么数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆