Change base URL

System Information
  • Strapi Version: 4.0.0
  • Operating System: CentOS (docker)
  • Database: PostgreSQL
  • NPM Version: 14.19.1
  • Yarn Version: 1.22.17

I deploy strapi via docker on CentOS server. When I try to initialization strapi, I get error about:

main.cd1c939f.js:2 Refused to connect to 'http://localhost:1337/admin/init' because it violates the following Content Security Policy directive: "connect-src 'self' https:".

How I understand, it’s connected with with host url. How I can change this url?
Thanks!

1 Like

Hello! You can manage basically Nginx reverse proxy for routing your Strapi admin / API routes and your frontend routes. And you need to pass proxy name as container service name (I attached sample Nginx config at end of the answer)

Check my Dockerized Strapi v4 + Next.js + Nginx boilerplate repo on Github: https://github.com/buraste/strapi-nextjs-docker-boilerplate

Follow this documentation for preparing configs: Nginx Proxying - Strapi Developer Docs

Also check answers on the question: Can Strapi run in a reverse proxied container using NGinx?

server {
    listen 80;
    server_name localhost;
    server_tokens off;
    client_max_body_size 20M;

    location / {
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Url-Scheme $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://frontend:3005;
    }

    location /_next/webpack-hmr {
        proxy_pass http://frontend:3005/_next/webpack-hmr;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location /strapi/ {
        rewrite ^/strapi/?(.*)$ /$1 break;
        proxy_pass http://backend:1337;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }

    location /strapi/_health {
        rewrite ^/strapi/_health/?(.*)$ /$1 break;
        proxy_pass http://backend:1337;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}