title: Wordpress on Docker Not Loading Proper Pages: Nginx Sending 301 after 404 and /$uri/index.php not found error (no such file or directory)
body: <p>The task at hand here is to migrate production to dev envrinoment on Docker. So far, I've got PHP and Nginx running on separate container because we will need to have many different containers for all of our different websites, but the same nginx image.</p>
  
  <p>I've got the main page to load, but from the way it looks, WordPress is not loading its pages by it's custom URI's, and instead it's trying to use the URI as an actual subdirectory, and then load <code>index.php</code>.</p>
  
  <p>I've included her my <code>nginx.conf</code>, <code>docker-compose.yml</code>, and <code>/var/log/nginx/error.log</code> output.</p>
  
  <p>When migrating a working WordPress site from Prod to Docker, only the initial page loads.</p>
  
  <p>When I navigate to <code>local.www.website.com</code>, I do receive a proper response: the front page. </p>
  
  <p>When I click any of the sub-links, or type in the URL: <code>http://local.www.website.com:8080/khat/, I receive an error in the browser:</code>local.www.website.com refused to connect.`</p>
  
  <p>When I use curl: <code>curl -v http://local.www.greenhousetreatment.com:8080/khat/</code> I get a 301.</p>
  
  <p>When I check the Nginx Error Logs (/var/log/nginx/errors.log`, I get: </p>
  
  <pre><code>2018/11/05 21:37:33 [error] 187#187: *45 
  "/var/www/website.com/current/html/khat/index.php" is not 
  found (2: No such file or directory), client: 172.26.0.1, server: 
  local.www.website.com, request: "GET /khat/ HTTP/1.1", host: 
  "local.www.website.com:8080"
  </code></pre>
  
  <p>My <code>website.conf</code> nginx file looks like this: </p>
  
  <pre><code> server {
     server_name local.www.website.com;
     root /var/www/website.com/current/html;
     index index.php;
  
     access_log  /var/log/nginx/access.log;
     error_log /var/log/nginx/error.log warn;
  
  
     location = /robots.txt  { access_log off; log_not_found off; }
     location = /favicon.ico { access_log off; log_not_found off; }
  
     location / {
        try_files $uri $uri/ /index.php?$args;
     }
  
     error_page 404 = /index.php?$args;
  
     # include /var/www/website.com/current/app/conf/nginx/redirects.conf;
  
     location ^~ /wp-content/uploads/ {
         proxy_pass https://s3-us-west-2.amazonaws.com/website.com/uploads/;
     }
  
     location ~* ^/listings/(.*[^/])$ {
         return 301 /listings/$1/;
     }
  
     # CSS and Javascript
     location ~* \.(?:css|js)$ {
         expires 30d;
         access_log off;
         add_header Cache-Control "public";
     }
  
  
     location ~ \.php$ {
         include fastcgi_params;
         fastcgi_pass php:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param REMOTE_ADDR $http_x_forwarded_for;
         fastcgi_param DEFAULT_REMOTE_ADDR $remote_addr;
         fastcgi_param APP_ENV "prof";
         fastcgi_param APP_WP_DB_NAME "website.com";
         fastcgi_param APP_WP_DB_USER "root";
         fastcgi_param APP_WP_DB_PASSWORD '1234'; 
         fastcgi_param APP_WP_DB_HOST "mysql:3306";
         fastcgi_param APP_WP_S3_UPLOADS_BUCKET "website.com"; 
         fastcgi_param APP_WP_S3_UPLOADS_KEY "1234";
         fastcgi_param APP_WP_S3_UPLOADS_SECRET '123/123/+123'; 
         fastcgi_param APP_WP_S3_UPLOADS_REGION "us-west-2"; 
     } 
  }
  </code></pre>
  
  <p>I have my nginx container exposed on ports: "8080:80", and my php-fpm exposed on "9000:9000"</p>
  
  <p>Here is my <code>docker-compose.yml</code></p>
  
  <pre><code>version: "3"
  services:
    web: 
      image: nginx:latest
      container_name: ght-nginx
      ports:
        - "8080:80"
      volumes:
        - ./website.com/current:/var/www/website.com/current
        - ./etc/nginx/sites-available/ght-nginx.conf:/etc/nginx/conf.d/site.conf
        - ./website.com/shared/logs/:/var/log/nginx/
        - ./etc/nginx/nginx.conf:/etc/nginx/nginx.conf
      links:
        - php
    php:
      image: php7.0-fpm-aac
      container_name: ght
      volumes:
          - ./website.com/current:/var/www/website.com/current
          - ./website.com/shared/logs/:/var/log/nginx/
          - ./sites/php/sites.conf:/etc/php/7.0/fpm/pool.d/php-fpm.conf
  
      ports:
        - "9000:9000"
  
  
   mysql:
     image: mysql:5.7
     container_name: ght-mysql
     ports:
       - "3306:3306"
     environment:
       MYSQL_ROOT_PASSWORD: 1234
     volumes:
       - ./mysql/library/:/var/lib/mysql
       - ./mysql/dumps/:/tmp/mysql/dumps
  </code></pre>
  
  <p>What am I missing? I've tried changing the exposed port in docker-compose to <code>9000:80</code>, I've tried adding AND removing</p>
  
  <pre><code>location / {
     try_files $uri $uri/ /index.php?$args;
  }
  </code></pre>
  
  <p>I've tried adding the following block of code to the bottom of the <code>wp-config.php</code></p>
  
  <pre><code> define('WP_HOME','http://local.www.website.com:8080');
   define('WP_SITEURL','http://local.www.website.com:8080');
  </code></pre>
  
  <p>I'm not sure what else needs to be done. Any help would be greatly appreciated. </p>