所有返回404的路线(“ /”除外)

时间:2019-06-14 09:03:47

标签: laravel nginx laravel-5

我已在arch linux上运行的nginx服务器上成功安装了laravel应用程序。但是,当我尝试在网络浏览器中查看该应用程序时,除默认的“ /”外,所有路由均返回404。我知道这是因为我有make:auth,但是我无法到达注册和登录页面。

我按照我在Google上找到的说明进行操作,并在sites-available中创建了两个文件夹sites enabled/etc/nginx/。然后,我在/etc/nginx/sites-available的{​​{1}}中为可用的站点创建了laravel应用程序的配置文件,称为niko

这是我的配置文件ln --symbolic /etc/nginx/sites-available/niko /etc/nginx/sites-enabled/niko的内容。

/etc/nginx/sites-available/niko

在我的server { listen 80; server_name niko; #charset koi8-r; #access_log logs/host.access.log main; location / { root /usr/share/nginx/html/niko/public; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; root /usr/share/nginx/html/niko/public; include fastcgi.conf; } } 中,此行位于/etc/nginx/nginx.conf块的结尾}上方:
http {} 当我检查nginx错误日志(include /etc/nginx/sites-enabled/*;)时,我发现以下条目:

/var/log/nginx/error.log

我已经拔了好几个小时,因为我不知道在哪里检查。我已经尝试了几件事,但似乎没有任何效果。感谢您的支持。

更新: 我的新2019/06/14 10:59:22 [error] 5429#5429: *3 directory index of "/usr/share/nginx/html/niko/" is forbidden, client: 192.168.1.101, server> 2019/06/14 10:59:36 [error] 5429#5429: *3 open() "/usr/share/nginx/html/niko/public/login" failed (2: No such file or directory), clie> 2019/06/14 10:59:36 [error] 5429#5429: *3 open() "/usr/share/nginx/html/niko/public/login" failed (2: No such file or directory), clie> 2019/06/14 10:59:38 [error] 5429#5429: *3 open() "/usr/share/nginx/html/niko/public/login" failed (2: No such file or directory), clie> 2019/06/14 10:59:38 [error] 5429#5429: *3 open() "/usr/share/nginx/html/niko/public/login" failed (2: No such file or directory), clie> 2019/06/14 11:26:53 [error] 5429#5429: *7 open() "/usr/share/nginx/html/niko/public/login" failed (2: No such file or directory), clie> 2019/06/14 11:26:53 [error] 5429#5429: *7 open() "/usr/share/nginx/html/niko/public/login" failed (2: No such file or directory), clie> 2019/06/14 11:27:01 [error] 5429#5429: *7 open() "/usr/share/nginx/html/niko/index.php/login" failed (2: No such file or directory), c> 2019/06/14 11:27:01 [error] 5429#5429: *7 open() "/usr/share/nginx/html/niko/index.php/login" failed (2: No such file or directory), c> 2019/06/14 11:27:04 [error] 5429#5429: *7 open() "/usr/share/nginx/html/niko/index.php/login" failed (2: No such file or directory), c> 2019/06/14 11:27:04 [error] 5429#5429: *7 open() "/usr/share/nginx/html/niko/index.php/login" failed (2: No such file or directory), 在这里

/etc/nginx/sites-available/niko

更新1 server { listen 80; server_name niko; root /usr/share/nginx/html/niko/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; location / { try_files $uri /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } } 给出:

namei -l /usr/share/nginx/html/niko/

1 个答案:

答案 0 :(得分:0)

Laravel要求您稍微更改一下nginx.conf文件,以使其正常工作。

查看Laravel Documentation中可用的示例conf文件。

server {
    listen 80;
    server_name example.com;
    root /example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}