silexphp / Silex-Skeleton

A skeleton to get started with Silex
MIT License
780 stars 197 forks source link

Page not Found #24

Closed russellseymour closed 9 years ago

russellseymour commented 10 years ago

Hello,

I have just cloned this project to understand how the profiler works, but when I try to access the 'index_dev.php' page I get an HTTP 404 error with a dialog box asking if I want to open the profiler.

It then takes me to a another page and it states that 'Page not found'.

I had to create a 'main.css' page as that was missing, but that has not fixed the problem. I can see that lots of files are being created in the /var/cache directory but I do not see the toolbar or any useful information.

I am sure I am missing something obvious.

thanks, Russell

russellseymour commented 10 years ago

UPDATE:

The error I get is this:

An error occurred while loading the web debug toolbar (404: Not Found)

So I am missing something to load the toolbar, but cannot work out what.

lschricke commented 10 years ago

Hello Russell,

Are you using Apache as your web server? If you are, I think it's probably an issue with the configuration of your .htaccess file.

russellseymour commented 10 years ago

Hello, thanks for the response ;-).

I am using (or trying to use) Nginx for this. But as the profile directory is outside of the webroot this might be the problem. Does the Profiler need an alias at all? I thought this was taken care of with the profile mount point of '_profiler'.

Russell

On 25 April 2014 15:37, lschricke notifications@github.com wrote:

Hello Russell,

Are you using Apache as your web server? If you are, I think it's probably an issue with the configuration of your .htaccess file.

— Reply to this email directly or view it on GitHubhttps://github.com/silexphp/Silex-Skeleton/issues/24#issuecomment-41399495 .

lschricke commented 10 years ago

Hello, I'm afraid I won't be able to help you with Nginx. I assume you've read the documentation regarding the configuration of the nginx web server: http://silex.sensiolabs.org/doc/web_servers.html#nginx?

jrschumacher commented 10 years ago

@russellseymour Can you post your server config for this project?

ffflabs commented 10 years ago

@jrschumacher this is my vhost. "local.ffflabs.com" is just an alias for localhost, because I have a lot of projects running locally.

  server {
        listen 80;
        server_name  local1.ffflabs.com;
        error_log  /var/www/error_logs/local1_error.log;
        access_log /var/www/error_logs/local1_access.log ;

        root   /home/ffflabs/git/silex-skeleton/web;

        location = / {
                try_files @site @site;
        }

        location / {
              try_files $uri $uri/ @site;
        }

        location ~ \.php$ {
                return 404;
        }

        location @site {
                fastcgi_pass  127.0.1:9000;
                include fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME $document_root/index_dev.php;
        }
 }

note that the doc root is set to the "web" subfolder

jrschumacher commented 10 years ago

This seems overly complex

server {
    server_name silex-skeleton.dev;
    listen silex-skeleton:80;

    root /Users/jrschumacher/sites/silex-skeleton/web;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_param APP_ENV dev;
        include fastcgi-php.conf;
    }
}
jrschumacher commented 10 years ago

@russellseymour and my fastcgi-php.conf

# fastcgi-php.conf

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
mTorres commented 9 years ago

I've managed to reproduce this error and in fact it is an issue with Nginx proposed configuration. I've copied and adapted the Symfony's one and created a pull request on Silex repo to solve this issue.

My proposal is as follows:

server {
    server_name domain.tld www.domain.tld;
    root /var/www/project/web;

    location / {
        # try to serve file directly, fallback to front controller
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/(index|index_dev)\.php(/|$) {
        # the ubuntu default
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        # for running on centos
        #fastcgi_pass   unix:/var/run/php-fpm/www.sock;

        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;

        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/index.php/some-path
        # Enable the internal directive to disable URIs like this
        # internal;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}
mTorres commented 9 years ago

@fabpot, I think you can safely close this one as e9bd89b is merged

fabpot commented 9 years ago

@mTorres Thanks for the heads up.

germain-italic commented 8 years ago

In case somebody else encounters the same error and runs Apache, put this in your .htaccess:

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    #RewriteBase /path/to/app
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
</IfModule>