title: Install wordpress in subdirectory with docker-compose and nginx
body: <p>I am going to build a website with docker-compose.</p>
  <p>When user enter the root directory, it goes to the web app. When the user enter the <a href="http://example.com/blog" rel="nofollow noreferrer">http://example.com/blog</a>, it should redirect to the wordpress.</p>
  <p>In order to do so, i have config the docker-compose like this</p>
  <pre><code>version: &quot;3&quot;
  
  services:
  
    nginx:
      image: nginx:latest
      depends_on:
        - web-app
        - wordpress
      volumes:
        - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      ports:
        - 80:80
  
    mysql:
      image: mysql:5.7.29
      container_name: mysql
      restart: always
      volumes:
        - ./data/mysql/data:/var/lib/mysql
  
    wordpress:
      depends_on:
        - mysql
      image: wordpress:latest
      ports:
        - 8000:80
      restart: always
      volumes:
       - ./data/blog:/var/www/html/wp-content
       - ./blog/wp-config.php:/var/www/html/wp-config.php
  
    web-app:
      build: ./app
      depends_on:
        - mysql
      restart: always
      command: npm start
      environment:
        - TZ=UTC
        - NODE_ENV=production
  
  networks:
    default:
      external:
        name: common
  </code></pre>
  <p>And this is my nginx config</p>
  <pre><code>worker_processes auto;
  events {
      worker_connections 1024;
  }
  http {
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
      log_format main '[$time_local] $remote_addr - $request request_time: $request_time';
      access_log /var/log/nginx/access.log main;
  
      gzip on;
      gzip_http_version 1.1;
      gzip_vary on;
      gzip_comp_level 6;
      gzip_proxied any;
      gzip_types text/plain text/html text/css application/json application/javascript application/x$
      #                        make sure gzip does not lose large gzipped js or css files
      #                        see http://blog.leetsoft.com/2007/07/25/nginx-gzip-ssl.html
      gzip_buffers 16 8k;
  
      server {
          listen 80;
          charset utf-8;
  
          location /blog/ {
              proxy_set_header  Host               $host;
              proxy_set_header  X-Real-IP          $remote_addr;
              proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
  
              proxy_pass http://wordpress;
          }
  
          location / {
              proxy_http_version 1.1;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection &quot;upgrade&quot;;
              proxy_set_header Host $http_host;
              proxy_set_header X-NginX-Proxy true;
              proxy_redirect off;
              proxy_pass http://web-app:3000;
          }
  
      }
  } 
  </code></pre>
  <p>And I have updated the wp-config.php and set the website url.</p>
  <pre><code>define('WP_SITE_URL', 'https://example.com/blog');
  define('WP_SITEURL', 'https://example.com/blog');
  define('WP_HOME', 'https://example.com/blog');
  </code></pre>
  <p>However, when I enter to <a href="https://example.com/blog" rel="nofollow noreferrer">https://example.com/blog</a>, it return the <code>ERR_TOO_MANY_REDIRECTS</code> response.</p>
  <p>I have searched a lot articles and some of that say it is because I am using cloudflare. How can I solve the above problem?</p>