Ubuntu 18.04 Laravel 5.7 Nginx 1.14 Laravel路由不起作用

时间:2019-02-10 15:04:21

标签: php laravel nginx

我最近将服务器从apache迁移到nginx,使用apache时,我有一个使用Laravel框架的工作站点。

由于某种原因,除基本索引页面外,没有其他页面会返回404错误。我确信它与我的nginx配置有关。我当前的配置如下所示。

server {
    listen 80;

    server_name munkeemagic.munkeejuice.co.uk;

    root /var/www/html/munkeemagic/mtg-webby/mtg/public;
    index index.php index.html;

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

    location ~* \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

我已检查确保为nginx用户使用的用户www-data设置了所有文件权限。我什至尝试更改

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

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

但这没有任何影响,我仍然看到相同的问题。

因此,基本上,如果我使用此配置,则导航到http://munkeemagic.munkeejuice.co.uk,然后显示页面

如果我转到http://munkeemagic.munkeejuice.co.uk/login,则会收到404错误。

有人知道我在做什么错吗?

在遵循user3647971的建议之后,我对配置进行了如下修改:

server {
listen 80;

server_name munkeemagic.munkeejuice.co.uk;

root /var/www/html/munkeemagic/mtg-webby/mtg/public;

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

index index.php index.html;

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;
}
}

我已经重新启动nginx进行更改,并且还清除了路由缓存,但是不幸的是我仍然遇到相同的问题。

1 个答案:

答案 0 :(得分:0)

好了,找出问题了,我有点傻。我的默认配置覆盖了我的网站特定配置。我取消链接默认配置,重新启动了nginx,一切开始正常运行。