如何在nginx的子目录中安装symfony2应用程序【JAVA教程】

!
也想出现在这里? 联系我们
信息

如何在nginx的子目录中安装symfony2应用程序,第1张

概述如何在nginx的子目录安装symfony2应用程序

我需要在同一主机上安装多个symfony2应用程序,但在不同的子目录(或位置块)上。

有了这个configuration,当试图访问任何url时,Nginx会抛出一个“找不到文件”或redirect循环消息。

例:

/login -> /base/login /app1 -> /base/app1 /app2 -> /base/app2

当前configuration:

查看linux内核configuration选项

什么是windows命令行EXE的“并排configuration”,我该如何纠正?

如何在windows上的Jenkinsconfiguration中设置PATH环境variables?

监视Ruby脚本,使用Monit – 包括RVM

linux – 通用networkingconfiguration

root /base/default; #Points to an empty directory # Login Application location ^~ /login { alias /base/login/web; try_files $uri app_dev.PHP; } # Anything else location ~ ^/([w-]+) { alias /base/$1/web; try_files $uri app_dev.PHP; } location / { # Redirect to the login rewrite ^ /login redirect; } # Handle PHP location ~ .PHP$ { include fastcgi_params; fastcgi_split_path_info ^(.+.PHP)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param httpS off; fastcgi_pass unix:/var/run/PHP5-fpm.sock; }

在Nginxconfiguration中,caret ^本身是什么意思?

PHP启用<?=?>

linux高内核cpu使用率在内存初始化上

使用C#.net挂载其他用户configuration单元

如何在windows 7 Professional下启用ctfmon.exe

经过几个小时的时间才发现这个(sf2 doc没有解释如何cgi参数是需要和解释的,你需要通过Request.PHP去了解),所以我分享这个。

这是一个配置,在目录{subdir}中可以与sf2配合使用(并且禁止对{subdir} / web / *之外的其他文件进行网络访问)。

它适用于我的PHP-fpm(套接字)。

当然,用/ path / from / docroot / to / symfony_root /替换“{subdir}”,

开发环境可以通过在“{subdir}”中添加“dev”来选择(因为url中的app_dev.PHP不再适用于这个conf)

server { # general directives location ~ ^/{subdir}(/.*)$ { try_files /{subdir}/web$1 @sf2; } location ~ ^/{subdir}dev(/.*)$ { expires off; try_files /{subdir}/web$1 @sf2dev; } location @sf2 { expires off; fastcgi_pass {your backend}; include fastcgi_params; fastcgi_param SCRIPT_filename $document_root/{subdir}/web/app.PHP; fastcgi_param SCRIPT_name /{subdir}/app.PHP; fastcgi_param REQUEST_URI /{subdir}$1; } location @sf2dev { expires off; fastcgi_pass {your backend}; include fastcgi_params; fastcgi_param SCRIPT_filename $document_root/{subdir}/web/app_dev.PHP; fastcgi_param SCRIPT_name /{subdir}dev/app_dev.PHP; fastcgi_param REQUEST_URI /{subdir}dev$1; } # other location directives # if some others apps needs PHP,put your usual location to cactch PHP here }

我希望这有助于(没有任何错误配置),给予没有任何保证…

当然,如果你不需要,你可以选择prod / dev conf。 而且你可以使用var和只有一个@ sf2位置来代替:

set $sf2_root /{subdir}; location ~ ^/{subdir}(/.*)$ { set $sf2_prefix /{subdir}; set $sf2_ctrl app.PHP; try_files $sf2_root/web$1 @sf2; } location ~ ^/{subdir}dev(/.*)$ { set $sf2_prefix /{subdir}dev; set $sf2_ctrl app_dev.PHP; expires off; try_files $sf2_root/web$1 @sf2; } location @sf2 { expires off; fastcgi_pass {your backend}; include fastcgi_params; fastcgi_param SCRIPT_filename $document_root$sf2_root/web/$sf2_ctrl; fastcgi_param SCRIPT_name $sf2_prefix/$sf2_ctrl; fastcgi_param REQUEST_URI $sf2_prefix$1; }

这是“/ front /”子目录下symfony2的一个更简单的配置。 路线生成和资产正常工作。

配置

set $frontRoot /your/project/path/web; set $sfApp app_dev.PHP; # Change to app.PHP for prod location /front/ { # Static files root $frontRoot; rewrite ^/front/(.*)$ /$1 break; try_files $uri @sfFront; } location @sfFront { # Symfony fastcgi_pass PHPfcgi; include fastcgi_params; fastcgi_param SCRIPT_filename $frontRoot/$sfApp; fastcgi_param SCRIPT_name /front/$sfApp; fastcgi_param REQUEST_URI /front$uri?$args; fastcgi_param httpS off; }

一些解释

诀窍是让symfony相信app.PHP脚本在/ front /中,所以它会用这个路径生成路由和资产。

我看了一下Apache给MOD-PHP的使用相同的值。

SCRIPT_filename:PHP文件的绝对路径。 这里总是/your/project/path/app_dev.PHP

REQUEST_URI:用户输入的URI。 在这里,我们必须在文件服务位置(通过rewrite ^/front/(.*)$ /$1 break; )删除路径的开始时手动重新添加/front rewrite ^/front/(.*)$ /$1 break;

SCRIPT_name:值为/front/app_dev.PHP 。 这是最重要的部分。 Symfony将切断app_dev.PHP,并将其/front到所有路由。

总结

以上是内存溢出为你收集整理的如何在nginx的子目录中安装symfony2应用程序全部内容,希望文章能够帮你解决如何在nginx的子目录中安装symfony2应用程序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

© 版权声明
THE END
喜欢就支持一下吧
点赞101 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容