Reverse proxy from Nginx to Dockerized Wordpress is causing an infinite redirect loop

General Tech Bugs & Fixes 2 years ago

1 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 28 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

My Wordpress website should appear at http://192.168.122.50/blog/

I started out by creating this server block

server {
  server_name 192.168.122.50;
  listen 80;

  location /blog/ {
    proxy_pass http://localhost:8000; # My Wordpress site
  }
}

Next, I added the two following lines to my Wordpress config (wp-config.php):

define( 'WP_HOME', 'http://192.168.122.50/blog/' );                                                                                  
define( 'WP_SITEURL', 'http://192.168.122.50/blog/' );   

I keep getting infinite redirect loops to this URL: http://192.168.122.50/blog/wp-admin/install.php

Here is the HTTP response I receive, according to httpie:

HTTP/1.1 302 Found
Cache-Control: no-cache, must-revalidate, max-age=0
Connection: keep-alive
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Sun, 07 Apr 2019 15:13:50 GMT
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Location: http://192.168.122.50/blog/wp-admin/install.php
Server: nginx/1.12.2
X-Powered-By: PHP/7.2.17
X-Redirect-By: WordPress

I have attempted to fix this issue by adding the following lines after the proxy_pass, but to no avail.

proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

Also, I am using the wordpress:latest Docker image.

profilepic.png
manpreet 2 years ago

Wordpress uses apache web server internally to route request so i am assuming you are puting nginx on top of wp-apache stack.

you should able to do this by sending every request coming to nginx proxy passing to apache by simply using below block

server {
  server_name _;
  listen 80;
    location / {
       proxy_pass http://localhost:8000;
    }
}

1 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.