【问题标题】:Symfony 2: 404 Not Found Error when tryes to open /app_dev.phpSymfony 2:尝试打开 /app_dev.php 时出现 404 Not Found 错误
【发布时间】:2012-09-14 12:45:45
【问题描述】:

我在尝试打开时收到此错误消息

/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. **

错误。

【问题讨论】:

标签: symfony nginx http-status-code-404 symfony-2.1 profiler


【解决方案1】:

我知道这不是你问的,但可能会帮助未来搜索这个问题的人,就像@yvoyer 建议的那样,我的问题也是斜杠,我的服务器使用了 nginx 和 fpm,并且在 nginx // 中不是 euqal /,所以我不得不对我的虚拟主机 conf 进行一些修复,之后它运行良好。我只是将 conf 粘贴给需要它的人,或者建议一个更好的。

    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
    }

【讨论】:

    【解决方案2】:

    我遇到了同样的错误,但我发现当我输入 app_dev.php/ 时输出了该消息,但在请求 app_dev.php 时没有输出(注意尾部斜杠 /)。

    我认为这与路由器有关,但这只是一个有根据的猜测

    【讨论】:

      【解决方案3】:

      我的错误与 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 的建议。

      【讨论】:

        【解决方案4】:

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

        【讨论】:

        • 谢谢@Rafal,但我正在尝试打开 app_dev.php 文件,它来自 Symfony 网站。如何解决这个问题?
        【解决方案5】:

        它发生在我的开发环境中,所以我在我的 vhost 配置文件中注释了 DirectoryIndex 指令,所以现在我使用:http://127.0.0.1/app_dev.php 进入我的应用程序 并且不再有关于探查器的错误! 我使用 Symfony 2.3.x。

        【讨论】:

          【解决方案6】:

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

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

          【讨论】:

          【解决方案7】:

          请尝试注意您的 .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>
          

          【讨论】:

          • 请先阅读整篇文章:“我正在使用nginx,非常感谢您的帮助。”虽然您的评论适合 APACHE,但它会搞砸人们。
          猜你喜欢
          • 2017-10-19
          • 2012-09-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-02
          • 1970-01-01
          • 2018-10-27
          • 2021-06-16
          相关资源
          最近更新 更多