Symfony 2:尝试打开/app_dev.php时出现404未找到错误

14
我尝试打开 /app_dev.php 时收到了这个错误消息。
An error occurred while loading the web debug toolbar (404: Not Found).

Do you want to open the profiler?

当我点击确定时,我会得到以下错误:

app_dev.php/_profiler/5053258a822e1

并且

404 Not found

我正在使用nginx

非常感谢您的帮助。

编辑:这里是错误日志:

[error] 18369#0: *9 open() "/var/www/Symfony/web/app_dev.php/_wdt/5056f875afc98" failed (20: Not a directory), client: 127.0.0.1, server: symfony, request: "GET /app_dev.php/_wdt/5056f875afc98 HTTP/1.1", host: "symfony", referrer: "http://symfony/app_dev.php"
[error] 18369#0: *9 open() "/var/www/Symfony/web/404" failed (2: No such file or directory), client: 127.0.0.1, server: symfony, request: "GET /app_dev.php/_wdt/5056f875afc98 HTTP/1.1", host: "symfony", referrer: "http://symfony/app_dev.php"

编辑2:

当我尝试访问app_dev.php时,页面会打开,但没有工具栏。 当我尝试使用app_dev.php/时,我得到了

**Oops! An Error Occurred
The server returned a "404 Not Found".
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused. **

错误。


1
你能发布一下你的nginx错误日志吗?(不仅仅是浏览器中打印出来的内容!) - Florent
感谢你,Florent。我已经修改了我的问题。 - Milos Cuculovic
已解决,查看我的答案:http://stackoverflow.com/a/30313196/1700429 - Dahab
希望这个链接有所帮助,因为它与此相同。 https://dev59.com/110a5IYBdhLWcg3wdIfo#30300601 - aiai
7个回答

11
我知道这不完全是你所要求的,但它可能会帮助未来搜索此问题的人,就像 @yvoyer建议的那样,我的问题也是因为尾随斜杠,我的服务器使用了nginx和fpm,在nginx中,//并不等于/,所以我需要在虚拟主机配置上做一些修复,然后它就可以正常工作了。我将把配置粘贴给需要的人,或者建议更好的一个。
    location / {
            try_files $uri @pass_to_symfony;
    }

    location ~ /app_dev.php/ {
            try_files $uri @pass_to_symfony_dev;
    }

    location @pass_to_symfony{
            rewrite ^ /app.php?$request_uri last;
    }

    location @pass_to_symfony_dev{
            rewrite ^ /app_dev.php?$request_uri last;
    }

    location ~ ^/app(_dev)?\.php($|/) {
            include fastcgi_params;
            fastcgi_pass   unix:/var/run/php5-fpm.sock; # replace with your sock path
    }

3

我曾经遇到过同样的错误,但后来发现只有在输入 app_dev.php/ 而不是请求 app_dev.php 时才会输出该消息(注意斜杠 /)。

我认为这与路由器有关,但这只是一个猜想。


1
我的错误与Nginx配置有关(使用Symfony 3.1),我只是编辑了Symfony推荐的Nginx配置。

http://symfony.com/doc/current/setup/web_server_configuration.html

也许是由于符号链接的原因,我不确定。
我将一小部分内容复制到Nginx默认配置中,并进行编辑以匹配所有.php文件。
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }


    # Symfony
    location ~ \.php(/|$) {
            fastcgi_pass unix:/var/run/php/php7.0-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;
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php7.0-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # With php7.0-fpm:
    #   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}

}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

我建议遵循Symfony的生产服务器规范。


0

在Symfony2中以开发者模式显示Web调试工具栏,页面应该具有有效的HTML。


谢谢@Rafal,但我正在尝试打开app_dev.php文件,这是来自Symfony网站的。如何解决这个问题? - Milos Cuculovic

-1

这发生在我的开发环境中,所以我在我的虚拟主机配置文件中注释了指令DirectoryIndex,现在我可以通过以下方式访问我的应用程序:http://127.0.0.1/app_dev.php,并且不再出现有关分析器的错误!我使用的是Symfony 2.3.x。


-1

我已经找到了解决方案(或多或少)。我拿了另一个现有的Symfony项目,现在一切都正常工作。我真的不知道为什么Symfony标准版本在我的情况下无法工作...如果有人需要空的Symfony项目,我可以上传存档。

编辑:这是工作中的Symfony 2.0模板:http://www.megafileupload.com/en/file/372986/Symfony-tpl-zip.html


请上传压缩文件,我遇到了同样的问题。 - tesmojones
2
这是Symfony模板。请享用:http://www.megafileupload.com/en/file/372986/Symfony-tpl-zip.html 如果您觉得有用,请点赞。谢谢。 - Milos Cuculovic

-3
请注意您的 .htaccess 文件,我也遇到了这个问题并解决了。
    <IfModule mod_rewrite.c>
    RewriteEngine On
        RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app_dev.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]    ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    RewriteRule .? %{ENV:BASE}/app_dev.php [L]        ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
    </IfModule>

    <IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the startpage to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 302 ^/$ /app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
    </IfModule>

5
请先阅读整篇文章: 我正在使用nginx。 非常感谢您的帮助。尽管您的评论对于APACHE是适用的,但它会让人们困惑。 - Zjoia

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接