如何使资产与Nginx子目录中的Symfony3一起使用

问题描述 投票:0回答:1

基于此问题, 如何在nginx的子目录中安装symfony2应用程序

我已经创建了可以在名为bcms4的子目录中工作的symfony3应用程序。 我已经设法使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;
}

}
php nginx symfony nginx-location
1个回答
0
投票

经过数小时的尝试,我设法做到了一点点破解。

这就是我添加到配置文件中的内容

location ~ ^/s(/.*).\w{1,5}$ {
    rewrite ^/s(/.*) /bcms4/web$1  break;
    return 404;
}

它将重写前缀为/ s并扩展到实际目录的文件。

也许会帮助某人。 我让问题待一会儿,也许有人有更好的解决方案,因为这对我来说似乎很棘手。

© www.soinside.com 2019 - 2024. All rights reserved.