System Information
- Strapi Version: 3.6.2
- Operating System: Ubuntu 18.04.5 LTS
- Database: Postgres
- Node Version: 12.18.3
- NPM Version: 7.20.0
- Yarn Version: 1.22.5
Hi! I’ve started seeing a strange issue recently in my deployed strapi instance. I have it deployed on https://xyz.com
, say. When I open my admin panel in the browser, it tries to hit http://localhost:1337/admin/init
instead of trying to hit https://xyz.com/admin/init
. This ends up with my admin panel being stuck in a “loading” state, and me getting a CORS error for trying to hit http://localhost:1337
.
My setup
I’ve got my instance deployed on an AWS EC2 instance, with pm2 managing the process. nginx routes requests to https, with certbot for the ssl. My strapi.conf
:
server {
# Listen HTTP
listen 80;
server_name www.xyz.com xyz.com;
# Redirect HTTP to HTTPS
return 301 https://$host$request_uri;
}
server {
# Listen HTTPS
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl;
server_name www.xyz.com xyz.com;
underscores_in_headers on;
# SSL config
ssl_certificate /etc/letsencrypt/live/xyz.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/xyz.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
# Proxy Config
location / {
rewrite ^/?(.*)$ /$1 break;
proxy_pass http://strapi;
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;
}
}
config/server.js
:
module.exports = ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
url: env("PUBLIC_URL", "http://localhost:1337"),
admin: {
auth: {
secret: env("ADMIN_JWT_SECRET", "default-secret-here"),
},
},
});
My pm2 ecosystem.config.js
:
module.exports = {
apps: [
{
name: 'my-project',
cwd: '/home/ubuntu/my-project',
script: 'yarn',
args: 'start',
interpreter: '/bin/bash',
...
env: {
NODE_ENV: 'staging',
...
PUBLIC_URL: 'https://xyz.com',
...
},
}
],
};
Things I’ve tried:
- Access by static IP instead of .xyz Domain Names | Join Generation XYZ - same result. Rules out nginx misconfig.
- Updating strapi to 3.6.5 - same result
- Delete
.cache
,node_modules
, runyarn build --clean
and run the server again - same result
I suspect there’s something up with the PUBLIC_URL
being passed to the admin panel. I peeked at the admin panel code a bit, it seems like it’s getting the base url value from strapi.backendURL
- any ideas where this is pulled from? Or any other ideas to try out?