WillyJimmyDev / simple-quiz

A simple quiz administration written in PHP with a MySQL backend. Uses Bootstrap 3 and Slim PHP micro framework
http://elanman.com/simple-quiz/
Apache License 2.0
164 stars 73 forks source link

404 when going to http://quiz/admin/ or http://quiz/quiz/6 #6

Closed pupadupa closed 9 years ago

pupadupa commented 9 years ago

Hi,

I'm using nginx. I create virtual host at http://quiz/ When I load main page everything is ok, but any other page gives me 404.

Here what I have in nginx error log:

2014/10/16 19:42:57 [error] 10209#0: *1 open() "/Users/username/Dev/www/quiz/public/quiz/6" failed (2: No such file or directory), client: 127.0.0.1, server: quiz, request: "GET /quiz/6 HTTP/1.1", host: "quiz", referrer: "http://quiz/"
2014/10/16 19:42:57 [error] 10209#0: *1 open() "/Users/username/Dev/www/quiz/public404" failed (2: No such file or directory), client: 127.0.0.1, server: quiz, request: "GET /quiz/6 HTTP/1.1", host: "quiz", referrer: "http://quiz/"

"/Users/username/Dev/www/quiz/public" - it's path to quiz public folder

Here is my nginx conf:

server {
        listen 80;
        root /Users/username/Dev/www/quiz/public;
        index index.php;
        server_name quiz;
        error_page   404  =   /404.php;
        error_page   403  =  /404.php;

    location / {
        include   /usr/local/etc/nginx/conf.d/php-fpm;
    }

    location = /info {
        allow   127.0.0.1;
        deny    all;
        rewrite (.*) /.info.php;
    }

    error_page  404     /404.html;
    error_page  403     /403.html;

}

Please tell me what is the problem?

WillyJimmyDev commented 9 years ago

Hi pupadupa, the problem is that the urls depend on .htaccess rules which route all requests for non-existent files through index.php; your typical front controller set up. Unfortunately for you, nginx doesn't work with .htaccess rules.

Try adding the following to your 'location /' config...

location / {
    include   /usr/local/etc/nginx/conf.d/php-fpm;
    try_files $uri $uri/ /index.php;
}

or

location / {
    include   /usr/local/etc/nginx/conf.d/php-fpm;
    try_files $uri $uri/ /index.php?$args;
}

Let me know how you get on.

pupadupa commented 9 years ago

ElanMan Thanks!

It worked for me (1st solution). Here are my new nginx conf:

server {
        listen 80;
        root /Users/pupadupa/Dev/www/quiz/public;
        index index.php;
        server_name quiz;
        error_page   404  =   /404.php;
        error_page   403  =  /404.php;

    location / {
        include   /usr/local/etc/nginx/conf.d/php-fpm;
        try_files $uri $uri/ /index.php;
    }

    location = /info {
        allow   127.0.0.1;
        deny    all;
        rewrite (.*) /.info.php;
    }

    error_page  404     /404.html;
    error_page  403     /403.html;

}