基于这个问题How to install symfony2 app in a subdirectory in nginx
我创建了 symfony3 应用程序,它在名为 bcms4 的子目录中工作。我已经设法使 php 与 PHP-FPM 一起工作,但我有资产问题。当我想获取资产时,它将请求定向到 app_dev 并显示 404,因为显然该路径不存在。
我的问题是如何使资产不被 app_dev 处理而是按预期下载?
所以当我进入
test.localhost/s/asdfad -> 它运行 symfony test.localhost/asdf -> 它运行位于主目录 test.localhost/s/assets/css/test.css 中的其他应用程序 -> 它将在目录 /var 中显示文件/www/test.localhost/bcms4/web/assets/css/test.css
我的 nginx 配置:
server {
listen 80;
root /var/www/test.localhost;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name test.localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ ^/s(/.*)$ {
try_files /s/web$1 /web$1 @sf2dev =404;
}
location @sf2dev {
expires off;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/test.localhost/bcms4/web/app_dev.php;
fastcgi_param SCRIPT_NAME /s/app_dev.php;
fastcgi_param REQUEST_URI /s$1;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_intercept_errors on;
}
}