Symfony2 nginx conf问题

时间:2017-07-17 06:45:06

标签: symfony nginx assetic

我有一个基于symfony2的项目,nginx作为服务器。我使用了symfony文档https://symfony.com/doc/current/setup/web_server_configuration.html#nginx

中的官方配置

当我使用app_dev.php访问该网站时,一切看起来都很好,路由工作正常。但是,js和css文件未从以下路径加载:/app_dev.php/css/compiled/main.css。 在日志中说:435 open()“/ var / www / web / app_dev.php / css / compiled / main.css”失败(20:不是目录)

看起来nginx认为app_dev.php是一个目录。配置有什么问题? 该项目还对css和js资源使用资产。

BR, FERI

1 个答案:

答案 0 :(得分:0)

我正在使用Docker,这是正常的:

server {
 server_name _;
 root /var/www/web;

location / {
    # try to serve file directly, fallback to app.php
    try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|app_test|config)\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
}



# PROD
location ~ ^/app\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    # Prevents URIs that include the front controller. This will 404:
    # http://domain.tld/app.php/some-path
    # Remove the internal directive to allow URIs like this
    internal;
}

error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}

您可以查看另一个用于symfony的整个docker配置https://www.github.com/api-platform/api-platform