【问题标题】:Site Configuration for Nginx Sub-FolderNginx 子文件夹的站点配置
【发布时间】:2012-11-10 02:00:47
【问题描述】:

我有一个项目,我想要在主域 (sitename.org/projectname) 的子文件夹中。这是一个带有 nginx 1.2.0 的 cakephp 1.3 项目。两天的大部分时间里,我一直在网上搜索/尝试解决方案。我最终会添加更多项目作为子文件夹,每个项目都有自己的根目录。

首先,如果站点位于根域中,则为工作配置。

server {
listen   80;
server_name sitename.org

    location / {
            root /export/home/sitename.org/projectname/app/webroot;
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$uri&$args;

             location ~ .*\.php$ {
                    include /etc/nginx/fastcgi_params;
                     fastcgi_pass 127.0.0.1:9000;
                     fastcgi_index index.php;
                     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            }


    }

}

我想要工作的是位置是子文件夹(sitename.org/projectname)。我用 try_files 和 fastcgi 尝试了各种配置,但我通常以“未指定输入文件”结束。也就是我的配置错误。

任何提示将不胜感激。

【问题讨论】:

  • 你真的明白/index.php?$uri&$args 永远不会在location /projectname 中到达你的location ~ .*\.php$ 吗?
  • 第二部分我省略了 /projectname simple,因为我无法让它工作,所以我正在寻找示例。即位置 /projectname/.*\.php$

标签: cakephp nginx cakephp-1.3


【解决方案1】:

通过将根更改为更高目录和重写路径的组合找到了我的答案。希望这可以帮助遇到类似情况的其他人。

location /projectname {
            root /export/home/sitename.org/;
            index index.php index.html index.htm;
            rewrite ^/projectname/(.*)$ /projectname/app/webroot/$1 break;
            try_files $uri $uri/ /projectname/app/webroot/index.php?q=$uri&$args;

            location ~ .*\.php$ {
                    include /etc/nginx/fastcgi_params;
                     fastcgi_pass 127.0.0.1:9000;
                     fastcgi_index index.php;
                    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            }

【讨论】:

    猜你喜欢
    • 2017-07-15
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 2015-03-03
    相关资源
    最近更新 更多