New Magento 2, nginx config error 403 forbidden

by farp332   Last Updated August 14, 2019 14:09 PM

After my installation of magento2 on Ubuntu, I get this error on localhost http://localhost/magento2/ 403 forbidden

I have to change the port to any other like 8080 in file /etc/nginx/sites-available/magento, in order to be able to load the website like this http://localhost:8080/magento2/

I know that nginx is able to server various sites, and I was expecting to use this http://localhost:80/magento2/ but I get error 403 forbidden

In my understanding as far as you have a root directory for each virtual hosts, the webserver will pull the site files from those locations, so it should not matter if this is the same port, if you specific the folder with the content after server name, in my case: http://localhost:80/magento2/

Is there anyone able to advice how this supposed to be configured with nginx?, thanks

My nginx config for magento is:

upstream fastcgi_backend {
     server  unix:/run/php/php7.2-fpm.sock;

 server {

     listen 80;
     server_name localhost/magento2;
     set $MAGE_ROOT /var/www/html/magento2;
     include /var/www/html/magento2/nginx.conf.sample;

Default is just:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {

                try_files $uri $uri/ =404;

Related Questions

How to switch between PHP versions on Ubuntu Nginx

Updated April 29, 2019 14:09 PM

Nginx Magento 2 403

Updated August 24, 2018 16:09 PM