使用 nginx 在 Debian 9 上部署 Laravel 项目

Deployment of Laravel project on Debian 9 using nginx

我尝试使用 nginx 将我的 Laravel 项目从本地主机部署到 Debian 服务器。首先,我遵循了本教程 LINK. Ended at the end of 5. chapter. I did not get any errors. Also I successfully connect Laravel project with server DB. I use Laravel version 6, so when i was modifying newly created config file on /etc/nginx/sites-available/myFile I used laravel's deployment tutorial LINK。由于我的服务器没有任何域,所以我只有 IP 可用。我的配置文件截图: Config file

当我尝试使用 IP 打开服务器页面时,出现错误 "This page isn't working"。这是因为我从 sites-enabled 中删除了 nginx 的默认文件。之前,我删除了默认文件,我得到的只是nginx的默认主页。

我尝试将 server_name 更改为 server_name _;server_name "";server_name IP。完成所有更改后,我重新启动了 nginx 服务器。

对运行我的Laravel项目有什么帮助吗?谢谢!!

编辑:项目路线:/var/www/html/OciNaCeste/BP_final

  1. 请使用以下配置
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name localhost;
    root /var/www/html/OciNaCeste/BP_final/public;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

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

  1. 然后重启nginx