Site Configuration for Nginx Sub-Folder

佐手、 提交于 2019-12-24 08:59:04

问题


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


    }

}

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.

Any tips would be appreciated.


回答1:


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;

            }


来源:https://stackoverflow.com/questions/13256606/site-configuration-for-nginx-sub-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!