Nginx子文件夹的站点配置 [英] Site Configuration for Nginx Sub-Folder

查看:416
本文介绍了Nginx子文件夹的站点配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主域(sitename.org/projectname)的子文件夹中有一个项目.这是一个使用nginx 1.2.0的cakephp 1.3项目.在过去两天的大部分时间内,我一直在Google上搜索/尝试在线解决方案.我最终将添加更多项目作为子文件夹,并且每个项目都有其自己的根.

I have a project that I want in a sub-folder off a main domain (sitename.org/projectname). It is a cakephp 1.3 project with nginx 1.2.0. I have been googling / trying solutions online for the better part of 2 days. I will be eventually adding more projects as sub-folders and each one will have its own root.

首先,如果站点位于根域中,则是有效的配置.

First, a working configuration if the site is placed in the root domain.

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


    }

}

我要开始工作的是在location是子文件夹(sitename.org/projectname)的情况下.我尝试过使用try_files和fastcgi进行各种配置,但通常以未指定输入文件"结束.也就是我的配置错误.

What I am trying to get working is when location is a sub-folder (sitename.org/projectname). I have tried various configs with the try_files and fastcgi but I usually end up with "No input file specified." aka my config is wrong.

任何提示将不胜感激.

推荐答案

找到了我的答案,将根更改为更高的目录并重写了路径.希望这对遇到类似情况的其他人有所帮助.

Found my answer with a combination of changing the root to a higher directory and rewrite path. Hope this helps others that run across a similar situation.

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;

            }

这篇关于Nginx子文件夹的站点配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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