2017-07-17 131 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