Nginx 移动项目后出现“文件未找到”错误

问题描述 投票:0回答:1

我目前正在将 Laravel 项目部署到 DigitalOcean Droplet。我的 Laravel 项目位于 /var/www 文件夹中,我想将项目移动到 /home/user 文件夹中。

我正在做的是将项目移动到所需的文件夹(/home/user)并更改 Nginx 配置:

来自

server {
    listen 80;
    server_name my-domain.com;
    root /var/www/laravel-project/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/php8.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

server {
    listen 80;
    server_name my-domain.com;
    root /home/user/laravel-project/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/php8.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

我只是更改了根文件夹,但即使重新启动 Nginx 后,我也会收到“文件未找到”错误。我是这种配置的初学者,我不知道我错过了什么。

如有任何帮助,我们将不胜感激!

laravel nginx deployment server digital-ocean
1个回答
0
投票

在这种情况下找不到很可能是由于用户权限,您用于 nginx 的用户没有 /home/user/whatever 的权限

如果您使用 nginx 常用的 www-data(检查 /etc/nginx/nginx.conf),请按照以下步骤操作:

更改所有权

sudo chown -R www-data:www-data /home/user/laravel-project 

更改权限

sudo chmod -R 755 /home/user/laravel-project
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.