1

The Problem.

No matter which URL I enter, all pages display the site's static front page. Known site URLs load the home page (but keep the URL entered) and should-be 404 paths like /I-know-you-do-not-exist-4343 also load the homepage (again, keeping the URL).

I can get to the WordPress admin without problem—it's just the front end of the site that's being screwy.

Also, the site works fine if I remove permalinks entirely and go with ?post=2. Site css/js/images are loading fine.

Just the facts, please:

  • Ubuntu 14.04
  • Apache 2.4.7
  • PHP 5.6.19-1
  • nginx 1.4.6 (front end)
  • Wordpress 4.4.2
  • mod_rewrite is enabled (conf file below)
  • permissions and ownership are all set. WP can rewrite the .htaccess file.

I generally define the two site url options dynamically in wp-config but have tried removing them as well as manually entering them both in the wp-config and directly into the database.

define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/wordpress');
define('WP_HOME',    'http://' . $_SERVER['SERVER_NAME']);

I’ve flushed my permalinks, crushed cookies and restarted apache just about 800 times.

I've disabled all plugins.

For source control reasons, Wordpress is in a subfolder ala Jaquith’s skeleton. Basically,

 /var/www/html/ 
 /var/www/html/app/ (wp-content)
 /var/www/html/media/ (wp-content/uploads) 
 /var/www/html/wordpress/

And here’s the bit from my conf file:

    DocumentRoot /var/www/html
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory "/var/www/html">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

Basic nginx->apache is working fine. It’s forwarding on :8080 and ports.conf as well as my virtual host site.conf file are listening for it. That is, if I put <?php phpinfo(); ?> into a static php file, all works as expected.

Initially, I had the infinite loop problem and have since added this to my site plugin:

remove_filter('template_redirect', 'redirect_canonical’);

Here's the nginx conf (basically the standard version the internetz say to use):

server {
   listen 80;
   root /var/www/html;
   index index.php index.html index.htm;

   server_name example.com;

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

   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;
   }

   location ~ /\.ht {
      deny all;
   }
}

And here are the Response Headers for a typical request:

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Thu, 17 Mar 2016 02:13:24 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 5600
Connection: keep-alive
Link: <http://example.com/wp-json/>; rel="https://api.w.org/", <http://example.com/>; rel=shortlink
Vary: Accept-Encoding
Content-Encoding: gzip
1

Your proxy is rewriting everything to index.php, which means that the backend never sees the original URI. The proxy should be transparent, like this:

server {
   listen 80;

   server_name example.com;

   location / {
     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;
   }
}
  • Marry me. Thanks for the explanation too—makes total sense. – Will Mar 19 '16 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.