asterix
asterix

Reputation: 225

Symfony2 nginx conf problems

I have a symfony2 based project with nginx as server. I used the official config from symfony documentation https://symfony.com/doc/current/setup/web_server_configuration.html#nginx

When I'm accessing the site with app_dev.php everything looks fine, routing is working. However js and css files not loading from the following paths: /app_dev.php/css/compiled/main.css. In the logs says: 435 open() "/var/www/web/app_dev.php/css/compiled/main.css" failed (20: Not a directory)

Looks like nginx thinks that app_dev.php is a directory. what is wrong with the configuration? The project also use assetic for css and js resources.

Br, Feri

Upvotes: 0

Views: 588

Answers (1)

Hamza Amrouche
Hamza Amrouche

Reputation: 126

This is what i'm using with Docker and this is working properly :

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;
}

You can take a look at one other whole docker configuration that is used too for symfony https://www.github.com/api-platform/api-platform

Upvotes: 0

Related Questions