简体   繁体   English

如何使用Nginx动态配置Cakephp应用程序?

[英]How to configure dynamically cakephp applications with nginx?

My problem is: I'm trying to configure a nginx with multiple cakephp applications (that will be added and removed from time to time). 我的问题是:我正在尝试使用多个cakephp应用程序配置nginx(将不时添加和删除)。 And I want to this configuration to be dynamic (if the subdirectory exists, then it will be loaded as a cakephp application, if not, 404). 而且我希望这种配置是动态的(如果子目录存在,那么它将作为cakephp应用程序加载,如果不存在,则为404)。

But the thing is: I cannot configure the nginx to serve correctly the root for each application (i do not want to put every location on my conf file). 但问题是:我无法配置nginx来正确地为每个应用程序提供根目录(我不想将所有位置都放在conf文件中)。

Ex: 例如:

/var/www/cakephp1 + /app/webroot/ Will be served as: www.mydomain.com/cakephp1
/var/www/cakephp2 + /app/webroot/ Will be served as: www.mydomain.com/cakephp2

I know how to make a configuration to run a single app. 我知道如何进行配置以运行单个应用程序。 Any ideas how to achieve this? 任何想法如何实现这一目标? With dynamic configuration? 具有动态配置?

You can use try_files for this easily. 您可以轻松地使用try_files If you match anything in your location directive, you can reuse any part of the matching group in your try_files directives to try multiple locations. 如果您匹配location指令中的任何内容,则可以重用try_files指令中匹配组的任何部分来尝试多个位置。 Also, you can use things such as $http_host to compose a different app root. 另外,您可以使用$http_host东西来组成另一个应用程序根。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM