我是Linux,PHP,Nginx和Linux的新手。 Symfony(是的,这将是一条很长的路:))而且我在创建一个新的Symfony项目时遇到了麻烦。
问题
我在这里浏览了网络和其他主题,但在访问app_dev.php
时我无法处理以下消息:
An error occurred while loading the web debug toolbar (404: Not Found)
Do you want to open the profiler?
如果我点击OK
,我会在http://testsite.local/Symfony/web/app_dev.php/_profiler/f63f84
上重定向,导致404错误。
配置
我有一个全新安装的Nginx和fpm,可以与à标准PHP站点一起使用。
app.php
和config.php
都运行良好(在config.php中没有发现任何问题)。
以下是我的Symfony项目的路径:/srv/www/testsite.local/public_html/Symfony/
这里是我的(基本)配置Nginx(/etc/nginx/sites-available/testsite.local
):
server {
server_name testsite.local;
access_log /srv/www/testsite.local/logs/access.log;
error_log /srv/www/testsite.local/logs/error.log;
root /srv/www/testsite.local/public_html;
location / {
index index.html index.htm index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
如果有人知道如何解决这个问题,请告诉我。任何帮助将非常感激:)
谢谢!
答案 0 :(得分:0)
此nginx配置应适用于您的开发环境
server {
server_name testsite.local;
root /srv/www/testsite.local/public_html;
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(/|$) {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
error_log /srv/www/testsite.local/logs/error.log;
access_log /srv/www/testsite.local/logs/access.log;
}
如果没有检查你的fastcgi_params(/etc/nginx/fastcgi_params
)
不要忘记重新加载你的nginx服务器
-
此配置混合了symfony documentation和您发布的配置
答案 1 :(得分:0)
@Miro& @VEBERArnaud:大家好,现在有效。
以下是基于您的建议的解决方案:
server {
server_name testsite.local;
access_log /srv/www/testsite.local/logs/access.log;
error_log /srv/www/testsite.local/logs/error.log;
root /srv/www/testsite.local/public_html;
location / {
# try to serve file directly, fallback to app_dev.php
try_files $uri /Symfony/web/app_dev.php$is_args$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}