This is a short article on how to make Apache, Nginx, and SSL work together.

I was going to run a blog at using WordPress and under SSL. The hosting of the blog is configured so that Nginx is a reverse proxy for an Apache-managed WordPress.

The Nginx configuration is as follows:

The upper part of the Nginx config listens to HTTP requests and redirects them squarely to the secure site. The secure site listens to incoming requests over the port 443 and passes them on to the Apache.

Apache listens to the non-secure port 8080. The Apache VirtualHost config is this:

The problem I had after getting this setup to run was that WordPress refused to see that it was working in SSL content. Since Apache is listening to the unsecure port, the server variables $_SERVER['HTTPS'] and $_SERVER['SERVER_PORT'] do not have values on and 443 respectively.

Because of this, half the links are rendered with the http schema and the mixed content doesn’t work. The function is_ssl() that makes this check, is located in wp-includes/load.php:

I tried first manipulating the server variables directly in wp-config.php , setting them like this:

This did not work as I expected. The link rendering worked fine, but the admin area refused to let me in under the admin account showing the error message:

Sorry, you are not allowed to access this page.

This was because the user variable was losing its “capabilites” parameters. I could not figure out exactly where and how, but that was it. In some part of the request timeline the user instance was OK, then suddenly it was not having any capabilites.

Fortunately, I can set server variables in the VirtualHost config using the SetEnv function. So I tweaked the Apache VirtualHost config like this:

After this change, the setup started working as I needed it to.