Skip to content

Strapi is ignoring the server config PUBLIC_URL and calling back to localhost:port from the browser #12129

@laurencefass

Description

@laurencefass

Bug report

Describe the bug

A clear and concise description of what the bug is.

Issue summary: Strapi is not picking up the PUBLIC_URL and /admin is calling back to a localhost:port URL.

I have a clean install of Strapi which I hope to access through a reverse proxied internet address and the browser is reporting errors trying to access localhost:port. I have defined a public url in server.js according to instructions here

/config/server/js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  url: env("PUBLIC_URL", "https://mydomain.wtf")
});


my nginx config is simple:

# strapi cms
server {
    listen 80;
    server_name myserver.wtf;
    location / {
        proxy_pass http://0.0.0.0:1337;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

bowser console errors:

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

(anonymous) @ main.b227e163.js:2
main.b227e163.js:2 Error: Network Error
    at e.exports (main.b227e163.js:2)
    at XMLHttpRequest.y.onerror (main.b227e163.js:2)
(anonymous) @ main.b227e163.js:2
main.b227e163.js:2 Refused to connect to 'http://localhost:1337/admin/init' because it violates the following Content Security Policy directive: "connect-src 'self' https:".

t.default @ main.b227e163.js:2
main.b227e163.js:2 Refused to connect to 'http://localhost:1337/admin/init' because it violates the document's Content Security Policy.

Steps to reproduce the behavior

  1. install strapi on a server
  2. configure nginx as above
  3. access admin for first time
  4. see console errors in the browser

Expected behavior

Strapi should replace "localhost:port" with PUBLIC_URL when calling back to the server

Screenshots

If applicable, add screenshots to help explain your problem.
image

Code snippets

If applicable, add code samples to help explain your problem.

System

  • Node.js version: 16.13
  • NPM version: 8.1.2
  • Strapi version: 4
  • Database: n/a
  • Operating system: docker/alpine 3.14

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions