Gii generator no works in yii2 adv template with docker

I’m working with yii2 advanced template with docker. When I tried to use gii generator, I got the error “Forbidden (#403) You are not allowed to access this page.”

I added I’ve added allowedIPs on backend/config/main-local
but nothing changes.

Searching in the forum, I based on this post. To generate a virtual host for frontend and backend. I did the changes on /etc/apache2/sites-enabled$ sudo nano 000-default.conf

<VirtualHost *:80>
        ServerName frontend.test
        DocumentRoot /app/frontend/web
</VirtualHost>
<VirtualHost *:80>
        ServerName backend.test
        DocumentRoot /app/backend/web
</VirtualHost>

Also without success.
I am still with the problem. cannot access to gii generator

Here is the docker-compose file

version: '3.2'

services:

  frontend:
    build: frontend
    ports:
      - 20080:80
    volumes:
      # Re-use local composer cache via host-volume
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      # Mount source-code for development
      - ./:/app
      # virtual hosts
      - ./apache_conf:/etc/apache2/sites-enabled/

  backend:
    build: backend
    ports:
      - 21080:80
    volumes:
      # Re-use local composer cache via host-volume
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      # Mount source-code for development
      - ./:/app
      # virtual hosts
      - ./apache_conf:/etc/apache2/sites-enabled/

I guess, when you launch yii web application inside docker container the “127.0.0.1” ip is local ip of docker container, not your PC. While you open gii page with browser - you open it from your PC, not docker container, so nor “localhost” nor “127.0.0.1” will not work.

I suggest you change your configuration to

if (!YII_ENV_PROD) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
}

Your production application doesn’t need a Gii module at all. While your DEV environment does not need such security.

If you still need ip restriction, you should dive into searching your local PC ip relative to docker container network and use it in your config.