3

After rebooting the laravel-based website on a Ubuntu server using nginx, and configured everything properly (hopefully, at least it worked before), I can only access to the index page but not any other page - nginx keeps throwing 404 not found.

Thought it could be permission issue but I've already tried

sudo chown -R :www-data /var/www/foo-bar sudo chmod -R 775 /var/www/foo-bar/storage sudo chmod -R 775 /var/www/foo-bar/resources

But seems not helping. And here is my nginx config file:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    root /var/www/foo-bar/public;
    index index.php index.html index.htm;

    server_name 120.25.203.113;

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

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Any idea? (Try http://120.25.203.113/ and click on the center button to have a look if interested!)

Update: the error log shows

[error] 24119#0: *77 open() "/var/www/ozunimate/public/student/register" failed (2: No such file or directory), client: 14.202.230.9, server: 120.25.203.113, request: "GET /student/register HTTP/1.1", host: "120.25.203.113", referrer: "http://120.25.203.113/"

"student/register" is not under /public and should be redirected (it used to be redirected normally before rebooting). Seems redirect not working anymore.

6
  • Can you update your question with a copy of your /etc/nginx/sites-enabled/default file (assuming you haven't created a different vhost file, in which case post that instead). Commented Mar 15, 2016 at 6:02
  • Sure, edited. @Joseph Commented Mar 15, 2016 at 6:22
  • Your config looks the same as mine and mine works fine on Laravel 5. Are you using Laravel 5 or 4? Anyway, I've upvoted your question so hopefully someone else will notice it. Commented Mar 15, 2016 at 7:01
  • I'm using Laravel 5. It worked before, after rebooting somehow it throws 404 error.. Thanks man for upvote! Commented Mar 15, 2016 at 7:11
  • you wrote the command 'sudo chown -R :www-data /var/www/foo-bar' but in your config the root is 'root /var/www/foo-bar/public;'. Are permission correct for the public folder? because 404 not found looks like nginx can't find the desired path. Can you enable error logging and check what's written to it? Commented Mar 15, 2016 at 7:54

2 Answers 2

2

Let me answer my question.

All the configs are fine - it turned out that the autoloader is not working. See in the error log nginx didn't redirect http requests to the right directories. It should be working fine, but I guess it's polluted somehow during rebooting.

Solution:
1. in the remote server: composer install
2. if not working, simply restore the entire server and boot again. It's a booting problem anyway.

Sign up to request clarification or add additional context in comments.

Comments

0

That might be right. However for me I was missing the following:

location / {
  # This line
  #try_files $uri $uri/ /index.php$is_args$args;
  # OR this
  try_files $uri $uri/ /index.php?$query_string;
}

That solved the problem!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.