Nginx 404 未找到错误。我该如何修复它?

发布于 2025-01-20 16:06:22 字数 1085 浏览 2 评论 0原文

我的项目使用 Laravel 8。

Php: 7.4

使用 AWS Nginx 服务器

我的应用程序主页很好。主页运行良好。但是,当我单击链接时,我收到来自 Nginx 的 404 Not Found 错误。

这是我在 nginx.conf 中的服务器配置

server {
    listen 80;
    listen [::]:80;
    server_name something.com;
    root /srv/something.com;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index 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.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

要做什么?要更改什么?

如何修复此错误?

I'm using Laravel 8 for my project.

Php: 7.4

Using AWS Nginx Server

My Application's Homepage is fine. The homepage is working well. But, when I'm clicking a link then I'm getting a 404 Not Found error from Nginx.

Here is my server config in nginx.conf

server {
    listen 80;
    listen [::]:80;
    server_name something.com;
    root /srv/something.com;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index 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.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

What to do? What to change?

How to fix this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文