0

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 web-server 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;
            }
  • Check by commenting htaccess first. – Mitro Aug 14 at 13:37
  • Hi @Mitro Thanks for helping here, I can't follow what you wrote, What should I do with "htaccess first". In my root there is that file magento@bonecrusher:/var/www/html/magento2$ ls -la .htaccess -rwxrwxr-x 1 www-data www-data 12076 jun 25 16:12 .htaccess Not sure how to proceed with your advice, cheers – farp332 Aug 14 at 13:51
  • rename .htaccess with any other name. Means it should not to be work and check after that – Mitro Aug 14 at 13:54
  • @Mitro I renamed the file .htaccess under root dir: /var/www/html/magento2, then edited file /etc/nginx/sites-available/magento to use port 80 (restarted nginx) and I got again 403 forbidden.... I renamed as well .htaccess under pub/ then under static/ just to understand whether this affects the site, and still same error. I have the site loading (with not styles, images, .. not ideas why this, will open another question) with port 8080, but every tutorial shows that you can have the nginx default page and a new site using same port 80. – farp332 Aug 14 at 14:18
0

drop all that and revert to default apache configuration. then create virtual host with proper domain name.

for example www.mynewshop.com

<VirtualHost *:80>
    ServerAdmin admin@mynewshop.com
    ServerName www.mynewshop.com
    ServerAlias www.mynewshop.com
    DocumentRoot /var/www/html/
             <Directory /var/www/html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
             </Directory>
</VirtualHost>

add this domain to your local hosts file: /etc/hosts

127.0.0.1 www.mynewshop.com

add your domain name to magento base url

php bin/magento setup:store-config:set --base-url="http://www.mynewshop.com/"
php bin/magento setup:store-config:set --base-url-secure="https://www.mynewshop.com/"
php bin/magento cache:flush

then just open it in your browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.