
Days ago, instead of using separate micro/nano servers, I try to collect all my sites onto a stronger server.
Several of my server were establish by wordpress with apache, therefore, I setup a Nginx server as reverse proxy and launch each site by customized LAMP docker image.
Things go pretty well with some configuration process, but I found something wrong with certain condition.
That is, when I try to access the wordpress site in sub folder (ex. https://www.rich-hsu.com/blog), the server will redirect the URL to a strange form: http://www.rich-hsu.com:443/blog
Although I can modify the URL with “https” and add the tailing slash (https://www.rich-hsu.com/blog/), this issue did make me dizzy. And I believe it will cause some impacts on SEO.
After hours of debugging, I got the root cause and solution.
The root cause is I’ve add a line in my Nginx server config file
proxy_set_header Host $host:$server_port;
You wonder what is this configuration doing. It helps to solve the “mixed content” issue of WordPress.
Since we apply SSL on each site with Nginx as proxy, the internal communications ( proxy_pass ) are just using HTTP. Therefore, you will get the main content in HTTPS but other resources in HTTP. And the browser will blocked such behavior.

Therefore, we have to do something for WordPress to know it should use “https” for all the resource accessing in HTML output. And the direct way (I though it is the direct way before this event…) is to set the configuration. WordPress will show the HTTPS in resource links by recognize the port 443.
And Boooooom! The bomb comes and I have no idea to avoid the “Mixed Content” issue and keep the redirection issue away.
With some search, there is no good solution to solve this issue. (I think the the “good” solution should be modification in configuration or add some plug-in only). We have to modify the WordPress code!!
So the total solution is
- Not to pass the port information to WordPress
Remove the “:$server_port” from the Nginx setting. However, you still have to pass the $host to WordPress to keep the resources host correct.
- Modify the code of WordPress
Since we did not pass the port (i.e. 443) to WordPress, we have to set the $_SERVER[‘HTTP’] flag on manually. Therefore, as we know the all the request will based on HTTPS as we defined in Nginx, we’re using the header “HTTP_X_Forwarded_Protocol” to make this happened. ( I know, some documents or articles use “Proto” but I like to make it more clearly. )
So we have 2 steps to do.
In Nginx setting, we add another line to pass the “https” information by header.
proxy_set_header X-Forwarded-Protocol “https”;
In WordPress, we need to add some logic as early as possible. (I did it by modify the first line of “wp-config.php”
if ($_SERVER[‘HTTP_X_FORWARDED_PROTOCOL’] === ‘https’) { $_SERVER[‘HTTPS’] = ‘1’; }
As the WordPress has a function named “is_ssl()”, and we should modify the function to hit the root cause, I believe the modification in configuration will be a better solution in maintenance perspective — the “is_ssl()” function might be overwritten after something such as upgrade.
As the result, all my sites work well without such confusing and annoying issue. : )