Search code examples
reactjsnode.jsnginxdockerfilevite

Blocked request. This host ("frontend_web") is not allowed


When building vite react in docker-compose application, a message appears when opening the web-site page Blocked request. This host ("frontend_web") is not allowed. To allow this host, add "frontend_web" to `server.allowedHosts` in vite.config.js.

I tried to use "vite-plugin-allowed-hosts" but it gives me an error when building the docker-container [ERROR] Failed to resolve entry for package "vite-plugin-allowed-hosts". The package may have incorrect main/module/exports specified in its package.json. [plugin externalize-deps]


Solution

  • A recent Vite update (6.0.11, to my knowledge) has introduced changes that "break" setups using proxies. To resolve this, you need to configure allowedHosts in your Vite configuration as told.

    In your case this should work:

    server: {
      allowedHosts: ['frontend_web'],
    }