Skip to content

Multiple domains caused 403 forbidden in Ngnix

I’m playing around with Magento2 version 2.4.8 but suddenly I’m getting the following error when trying to enable multiple domains ( mydomain.test & mydomain.com )

directory index of "/etc/nginx/html/" is forbidden, client: x.x.x.x, server: , request: "GET / HTTP/2.0", host: "mydomain.test"

And via HTTP i’m getting 403 Forbidden

  • I really don’t know how to solve this loop ?
  • What’s the right way to add a new domain to support ?
  • I’m also ok with what needs to be done to go back to the starting point

assistance is appreciated


What I was trying to do – enable multiple domains, i did that by adding everything needed inside the UI/Admin, but then it didn’t work, kept redirecting the .com -> .test

So from looking around I found the commandline:

bin/setup-domain mydomain.test
bin/setup-domain mydomain.com

From this point everything inside the Ngnix is working as expected … logs doesn’t say much..

Configuration looks like so:

# file: /etc/nginx/nginx.conf
...
include /etc/nginx/conf.d/*.conf;
# file: /etc/nginx/conf.d/default.conf
upstream fastcgi_backend {
  server unix:/sock/docker.sock;
}

server {
  listen 8000;
  return 301 https://$host$request_uri;
}

server {
  listen [::]:8443 ssl http2 ipv6only=on;
  listen 8443 ssl http2;

  ssl_certificate /etc/nginx/certs/nginx.crt;
  ssl_certificate_key /etc/nginx/certs/nginx.key;

  set $MAGE_ROOT /var/www/html;
  ...
  include /var/www/html/nginx[.]conf;
# file: /var/www/html/nginx.conf
empty
# file: /var/www/html/nginx.conf.sample
root $MAGE_ROOT/pub;
... file remains the same after setup ...