We’ve just launched up another blog called SaaS Book (SaaSBook.net) which will be about the SaaS lessons we’ve learned through our SaaS product development journey.

The set up on that site was nginx as a reverse proxy to other services on that particular server.

The set up is nginx => Apache no special cases this time. See the nginx conf at the end of this post.

When we attempted to install WordPress and the installer couldn’t find jQuery, styles etc.

Everything was correctly set up and nginx was correctly installed and proxying requests to Apache.

I can’t believe WordPress still doesn’t detect this automatically or maybe via a constant.

The fix is to add this block of code in your wp-config.php file. It will override the HTTPS and HTTP_HOST values so apache is happy.

The apache server is running on port 8080 and doesn’t have https/ssl activated because it is handled at another level by nginx on port 80

if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
	$_SERVER['HTTPS'] = 'on';
        $_SERVER['SERVER_PORT'] = 443;
}

if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
	$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

The nginx virtual host set up is this.

# /etc/nginx/sites-enabled/20-example.com.conf
server {
    server_name saasbook.net www.saasbook.net;
    listen 80;
	
	# when the SSL is generated enable these lines and replace the example domain with yours
    #listen 443 ssl http2;
    #ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    #ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

	location / {
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $remote_addr;
		proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080;
    }
}

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer