Report this

What is the reason for this report?

Redirect loop with Wordpress on Apache with nginx reverse proxy and HTTPS on Ubuntu 16

Posted on May 4, 2017

I’m experimenting with a DO droplet to host my Wordpress blog, setting it up myself because I’m difficult that way.

I configured Apache with TLS via Lets Encrypt and migrated my Wordpress blog over, and everything was working fine.

I then put nginx in front of Apache as a reverse proxy and configured nginx as the TLS terminator, redirecting any non-https to https using the tutorials here.

Now I can access any static files which are served up by nginx, and accessing a phpinfo() test file on Apache works fine. But accessing any Wordpress php files, like index.php or admin triggers a redirect loop.

What did I do wrong? Here’s my nginx config

# Default server configuration
#
server {
        listen 80;
        listen [::]:80;
        server_name demo.EXAMPLE.com;

        # redirect all http to https
        return 301 https://$server_name$request_uri;
}

server {
        # SSL configuration
        listen 443 ssl http2 default_server;
        listen [::]:443 ssl http2 default_server;
        include snippets/ssl-demo.EXAMPLE.com.conf;
        include snippets/ssl-params.conf;

        root /var/www/demo.EXAMPLE.com/public_html;

        index index.php index.html index.htm;

        server_name demo.EXAMPLE.com;

        location / {
                try_files $uri $uri/ /index.php;
        }

        # proxy PHP requests to Apache
        location ~ \.php$ {
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $host;
                proxy_pass http://127.0.0.1:8080$request_uri;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one

        location ~ /\.ht {
                deny all;
        }

}

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.