Score:0

Source site static resources are not loaded correctly after setting up a reverse proxy with Nginx Proxy Manager

jp flag

I created the Nginx Proxy Manager container and the Wordpress container using Docker. But when I set up the reverse proxy for the Wordpress container as usual (not Wordpress), I realized that Nginx is not properly proxying the static content (e.g. JS, CSS, images) of the source site (which is the service provided by the Wordpress container).

The browser's developer tools (F12) prompted the following: Mixed Content: The page at 'https://myDomain/wp-admin/setup-config.php' was loaded over HTTPS, but requested an insecure script 'http://myDomain/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.4.0'. This request has been blocked; the content must be served over HTTPS.

It should be noted that my Wordpress container does not provide an HTTPS service, so it is in fact the Nginx service provided by the Nginx Proxy Manager that reverse proxies the HTTP service provided by the Wordpress container with running the HTTPS service itself.

After searching, I added the following code to the Advanced Options in the corresponding Proxy Host in Nginx Proxy Manager:

Custom Nginx Configuration

location / {
     proxy_set_header X-Forwarded-Proto  $scheme; 
}

This does seem to be somewhat useful, at least being able to load images and stuff. But the problem is that what it loads is not Wordpress at all but the OpenResty welcome page.

I don't know what the problem is, I sincerely hope you can help me, if you would like more information to solve the problem please let me know, thanks.

Note:

I used the following container image:

jc21/nginx-proxy-manager:latest

wordpress:latest
Score:0
ws flag

The problem is that wordpress doesn't know it is being accessed over HTTPS, so its writing html containing (e.g.)

<img src="http://yoursite/wp-content/picture.png">

You might want to investigate this a bit further; its possible that core Wordpress is using the MUCH more sensible relative paths .... src="/wp-content/picture.png" but plugins vary enourmously in quality.

Adding this in your wp-config.php should fix most of the code....

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 
   strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
    $_SERVER['HTTPS'] = 'on';
}

(also assumes that your nginx is configured to add the header).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.