The reason for the unauthorized error is because nginx uses a user called www-data
.
It is also possible to add permissions without changing the user name, but There is also an easy way to change the user name used by nginx.
How to change nginx username:
$ sudo nano /etc/nginx/nginx.conf
# change user www-data to ubuntu
$ sudo systemctl restart nginx
Since adding only permissions is complicated, it is replaced with a link.