Question
Redirect loop with Wordpress on Apache with nginx reverse proxy and HTTPS on Ubuntu 16
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;
}
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×