[英]PHP 7.4, NGINX, Laravel 8 - only shows index page, all routes show 404
我在 AWS t2.nano Linux AMI ec2 实例上放置了一个 Laravel 8 应用程序。 我想首先说我已经在这里工作了大约一天。 我尝试了一些配置。
这是我尝试过的一些配置:
Laravel 8 文档中的默认 nginx 配置文件https://laravel.com/docs/8.x/deployment#nginx
这里引用的另一个非常相似的计算器溢出问题Laravel on nginx 说 404 对于除索引外的所有路由
归根结底,我无法让它正常工作。 我的索引页面加载了,但任何其他路由都以 404 页面结束。 您可以在此处查看该应用程序。 https://technology.dvemedia.com/
所以这里有一些技术规格和我的 conf 文件的当前状态。
# HTTP
server {
listen 80;
listen [::]:80;
server_name technology;
return 301 https://$host$request_uri; # Redirect to www
}
server {
listen 80;
listen [::]:80;
server_name technology.dvemedia.com;
root /var/www/html/technology/public;
index index.php index.html index.htm;
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.4-fpm.sock;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
我错过了什么或做错了什么,因为我无法让它去拯救我的生命。
试试这个:
## Nginx php-fpm Upstream
upstream dvemedia {
server unix:/var/run/php/php7.4-fpm.sock;
}
## Web Server Config
server
{
## Server Info
listen 80;
listen [::]:80;
server_name technology.dvemedia.com;
root /var/www/html/technology/public;
index index.html index.php;
## DocumentRoot setup
location / {
try_files $uri $uri/ @handler;
expires 30d;
}
## Disable .htaccess and other hidden files
location /. {
return 404;
}
## Rewrite all request to index
location @handler {
rewrite / /index.php;
}
## Execute PHP scripts
location ~ \.php$ {
try_files $uri = 404;
expires off;
fastcgi_pass dvemedia;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
并将所有优化/调整(如fastcgi_buffers
...)放在fastcgi_params
文件中
我做了一个错误的假设,认为我的 php-fpm 套接字会保持不变。 查看目录结构后,我的 7.4 套接字最终出现在这里。
fastcgi_pass unix:/var/run/php-fpm/www.sock;
这实际上修复了它并且一切正常。 当我为我的套接字编写路径时,我给出了错误的信息实际上是这样的。
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
如果我提供了正确的信息,@Latheesan 的答案很可能会奏效,当然要减去拼写错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.