1

我在子目录 www.mysite.com/shop/ 下运行 Lemonstand

这是我的柠檬摊位置规则:

# Lemonstand
location /shop {
    root /home/sites/mysite.com/public_html/shop/;
    index index.php;

    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_param SCRIPT_NAME index.php;
    fastcgi_param QUERY_STRING url=$uri&$args;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 32k;
    fastcgi_busy_buffers_size 64k;
}

我可以访问 mysite.com/shop 上的页面。

商店的所有 URL应该是这样的:

mysite.com/shop/category/freight
mysite.com/shop/products/dog-toy

实际上在页面上时,它们的结构如下:

mysite.com/category/freight
mysite.com/products/dog-toy

奇怪的是,即使我将正确的 URL 粘贴到浏览器,它也只会显示我的基本 /shop/ 页面,就好像其他页面不存在一样。任何人都可以帮忙吗?

4

2 回答 2

0

您需要从不同的位置块提供 php。

[编辑] 为避免与其他 php 脚本冲突,您可以使用命名位置。

location ^~/shop/ {
    root /home/sites/mysite/public_html;

    try_files $uri $uri/ @anotherPhpSite
}

location @anotherPhpSite {
    include fastcgi_params;

    # Defend against arbitrary PHP code execution
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    # More info:
    # https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_param SCRIPT_FILENAME $document_root/shop/index.php;
    fastcgi_param SCRIPT_NAME /shop/index.php;
    fastcgi_param QUERY_STRING url=$uri&$args;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 32k;
    fastcgi_busy_buffers_size 64k;

}
于 2013-03-21T12:43:34.613 回答
0

我的主要问题是表达式语法和配置结构。

好的。所以这是工作配置文件。最佳做法是将两个位置分开,并为它们使用一个 php 块。

首先是使用 silverstripe CMS 的主控制器块,这里我将数据直接传递给蓝宝石中的主控制器。

# Main silverstripe declaration
location / {
    index /sapphire/main.php;
    try_files $uri $uri/ /sapphire/main.php?url=$uri&$args;
}

第二个是我的商店在一个运行柠檬摊的子目录下。这主要是让表达式正确,然后将请求传递到相关路径的情况。我没有在这里设置另一个根或别名,因为该规则是从重写中继承的。

# Shop lemonstand files
location /shop/ {
    index index.php;
    rewrite ^/shop(.*)$ /shop/index.php?q=$1 last;
    try_files $uri $uri/ /shop/index.php?q=$1;
}

最后我使用了一个通用的 PHP 块,所以我不必在前两个中复制我的代码。所以任何通过前两个区块的东西都会进入这里。

# PHP controller
location ~ ^(.*?\.php)(/.*)?$ {
    fastcgi_split_path_info ^(.+?\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_pass 127.0.0.1:9000;

    fastcgi_index index.php;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 32k;
    fastcgi_busy_buffers_size 64k;
}
于 2013-03-27T09:47:02.030 回答