2015-10-24 6 views
1

Это моя конфигурация:Symfony 2 Nginx configuraiton выбрасывает ошибку 500

server { 
    server_name domain.com; 
    root /var/www/domain.com/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|config)\.php(/|$) { 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_split_path_info ^(.+\.php)(/.*)$; 
     include fastcgi_params; 
     # When you are using symlinks to link the document root to the 
     # current version of your application, you should pass the real 
     # application path instead of the path to the symlink to PHP 
     # FPM. 
     # Otherwise, PHP's OPcache may not properly detect changes to 
     # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 
     # for more information). 
     fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 
     fastcgi_param DOCUMENT_ROOT $realpath_root; 
    } 
    # PROD 
    location ~ ^/app\.php(/|$) { 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_split_path_info ^(.+\.php)(/.*)$; 
     include fastcgi_params; 
     # When you are using symlinks to link the document root to the 
     # current version of your application, you should pass the real 
     # application path instead of the path to the symlink to PHP 
     # FPM. 
     # Otherwise, PHP's OPcache may not properly detect changes to 
     # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 
     # for more information). 
     fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 
     fastcgi_param DOCUMENT_ROOT $realpath_root; 
     # 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/domain.com.error.log; 
    access_log /var/log/nginx/domain.com.access.log; 
} 

Сайт работает почта, domain.com/, но всякий раз, когда я открываю любой другой маршрут, как domain.com/test/ я получаю 500 внутренняя ошибка сервера.

Кроме того, когда я открываю среду разработчика, как domain.com/app_dev.php/test/ Я получаю сообщение об ошибке, что я не могу получить доступ к файлу app_dev.php.

Что случилось?

+0

Это может работать, как это официальная конфигурация Nginx из [symfony.com] (http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html#nginx), не могли бы вы предоставить дополнительную информацию о вашем приложении, например, ваш контроллер и файл 'routing.yml'? Что же касается 'app_dev.php' - доступ к этому файлу закрыт не из localhost по соображениям безопасности, вы можете сами посмотреть код и даже удалить защиту, если вам нужно. – chapay

+0

Также вы можете просмотреть свои журналы: '/ var/log/nginx/domain.com.error.log' и'/var/www/domain.com/app/logs/prod.log' для получения дополнительной информации. – chapay

+0

Журналы пустые - как в приложении, так и nginx. Как будто ничего не происходит, когда я вхожу в любой маршрут. – user99999

ответ

0

Попробуйте это:

server { 
listen    *:80; 

server_name   time.dev www.time.dev; 
client_max_body_size 1m; 

root /var/www/time/web; 
    index app_dev.php; 

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

location ~ \.php$ { 

    root /var/www/time/web; 
    fastcgi_index app_dev.php; 
    fastcgi_split_path_info ^(.+\.php)(/.*)$; 
    try_files $uri $uri/ /app_dev.php$is_args$args; 
    include /etc/nginx/fastcgi_params; 
    fastcgi_pass 127.0.0.1:9000; 

    fastcgi_param SCRIPT_FILENAME $request_filename; 
    fastcgi_param APP_ENV dev; 

} 
location/{ 
    root /var/www/time/web; 
    try_files $uri $uri/ /app_dev.php$is_args$args; 
    autoindex off; 
    index index.html index.htm index.php; 


    } 
    sendfile off; 
} 

Это скопировано с моей бродячей Dev машины.

https://gist.github.com/sfarkas1988/f781ef3015f7d794b6b2

+2

Пожалуйста, объясните, почему ваша конфигурация лучше официального. – chapay

Смежные вопросы