使用Nginx运行Laravel

首先,在/var/www/html下创建一个Laravel项目。

假设我们有一个名为/var/www/html/helloworld的项目,我们将/var/www/html/helloworld/public设置为Nginx的根目录。

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html/helloworld/public;
        index index.html index.htm index.php;

        server_name _;

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }

}

确认设置文件是否正确。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

重新启动Nginx

sudo systemctl restart nginx

我在下一个版本中进行了确认。

$ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)