まず、
/var/www/html 以下に Laravel のプロジェクトを作成します。
例えば
/var/www/html/helloworld というプロジェクトだとすると、
/var/www/html/helloworld/public を Nginx の root にします。
/etc/nginx/sites-available/default
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)