2017-07-17 67 views
0

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

当我使用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

+0

你的配置是什么? – eeXBee

回答

0

这是我使用的是什么泊坞,这是正常工作:

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 https://www.github.com/api-platform/api-platform