任何 AWS EB Laravel 路由都出现 404 Not Found nginx/1.16.1 [英] Any AWS EB Laravel route getting 404 Not Found nginx/1.16.1

查看:54
本文介绍了任何 AWS EB Laravel 路由都出现 404 Not Found nginx/1.16.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 AWS Elastic beanstalk 上部署了一个新的 laravel 7 应用程序.我注意到他们将 Apache 服务器更改为 Nginx 服务器.

<块引用>

在最后一个文件夹 elasticbeanstalk 中放置您的配置文件

例如laravel.conf

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

将应用程序上传到 EB 后,它会将文件复制到服务器上的相同位置并重新启动 NGINX.


额外

在某些情况下,这可能还不够,当您尝试前往任何特定路线时,您会得到一个

<块引用>

419 |页面已过期

要解决这个问题,只需通过 SSH 连接到您的实例,请转到项目位置并清除缓存

php artisan cache:clear

I've just deploy a new laravel 7 application on AWS Elastic beanstalk. I've noticed they changed the Apache server to Nginx server.

https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platform-history-php.html

This is my api backend URL: http://mappab-api-staging.mappab.com.br/

This is the login route: http://mappab-api-staging.mappab.com.br/login - 404 status.

Did you get the same problem? How can I fix it?

My php.conf placed at /etc/nginx/conf.d/elasticbeanstalk/ is:

root /var/www/html/public;

index index.php index.html index.htm;

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

location ~ /.ht {
   deny all;
}

location ~ /.well-known {
   allow all;
}

location ~ .(php|phar)(/.*)?$ {
    fastcgi_split_path_info ^(.+.(?:php|phar))(/.*)$;

    fastcgi_intercept_errors on;
    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_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  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;

    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_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO $fastcgi_path_info;
    fastcgi_pass   php-fpm;
}

解决方案

If you are using Amazon Linux 2 with Elastic Beanstalk with an NGINX server then you need to follow this documentation.

Basically all you need to do is create a folder structure mapping the NGINX config location you want to place you config file with .platform as the topmost folder this should be in your application root

i.e. in a laravel app create a folder called .platform in the same level as the app folder. Within this .platform folder create the following

/nginx/conf.d/elasticbeanstalk

so you have a folder structure like .platform/nginx/conf.d/elasticbeanstalk

in this last folder elasticbeanstalk place your config file

e.g. laravel.conf

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

Once you upload the application to EB it will copy the file to the same location on the server and restart NGINX.


Extra

In some cases this might not be enough and when you try to go to any specific route you'll get a

419 | PAGE EXPIRED

To fix that simply SSH into your instance, go to the project location and clear the cache

php artisan cache:clear

这篇关于任何 AWS EB Laravel 路由都出现 404 Not Found nginx/1.16.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆