Mixed content error after setting up https means I cannot open the admin

System Information
  • Strapi Version: 3.3.4
  • Operating System: ubuntu 18.04.4
  • Database: postgres
  • Node Version: v12.18.3
  • NPM Version: 6.14.6
  • Yarn Version:

I used the digital ocean one click strapi droplet .

at set up i could access the admin log in. but it would appear at the ip.address/admin and not at the domain.name/admin

I then set up https using certbot.

I then edited the /srv/strapi/strapi-development/config/server.js file ton include the url. as per [https://strapi.io/documentation/v3.x/deployment/nginx-proxy.html]

this file now looks like this

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
        url: env( 'https://sub.my.domain',''),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET'),
    },
  },
});

I am still running the development server

at this point the base url is being served over https but when i try to open the /admin url of the admin panel I get a mixed content error

Mixed Content: The page at 'domain.name'' was loaded over HTTPS, but requested an insecure resource 'http://ip.address/admin/init'. This request has been blocked; the content must be served over HTTPS.

I am guessing there is a further config somewhere ? any help gratefully received.

You are not using env function correctly.

env(param1,param2)

param1 is the ENV variable name.
param2 is the default value when param1 doesn’t exist.

In your case, you defined https://sub.my.domain as a variable name and env() expects to receive a value from it, but it doesn’t exist so it gets the default value, which is empty '' in your case. So your url right now is an empty string.

So the correct use of env() is:

url: env( 'PUBLIC_URL','https://sub.my.domain'), //PUBLIC_URL should be defined in your environment variables.

Thanks sunnyson, I have now updated the url line to read
url: env(‘PUBLIC_URL’, ‘https://sub.my.domain’),
however that has not affected the problem. the admin interface still tries to call a script at 'http://ip.address/admin/init'
and i still get a mixed content error

You should rebuild your project after modifying the url, since the url is added to build files during build and its not used from envs.

Rebuilding was the charm. Thanks sunnyson. You’ve really helped me out.

Hello,

Sorry to jump in but I am stuck here as well. One question before proceeding to rebuild… does it mean I will be losing all the content I have previously created in Strapi?

Hi Tjaun1
you should be fine. Rebuilding strapi did not nuke my content when i did this.

Yay! It worked. Thank you so much