Jer*_*vid 5 configuration nginx url-routing symfony
我需要在同一主机上但在不同的子目录(或位置块)上安装多个symfony2应用程序.
使用此配置,nginx在尝试访问任何URL时抛出"找不到文件"或重定向循环消息.
例:
/login -> /base/login
/app1 -> /base/app1
/app2 -> /base/app2
当前配置:
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;
}
dca*_*aud 15
花了几个小时才发现这个(sf2 doc没有解释如何需要和解释cgi参数,你需要通过Request.php来理解),所以我分享了这个.
这是一个配置,对于目录{subdir}中的sf2似乎没问题(并且禁止访问除{subdir}/web/*之外的其他文件).
它适用于php-fpm(socket).
当然,将/ {subdir}替换为/ path/from/docroot/to/symfony_root /
可以通过将"dev"添加到"{subdir}"来选择dev environnement(因为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;
  }
| 归档时间: | 
 | 
| 查看次数: | 6847 次 | 
| 最近记录: |