Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The reason why it is not working is that ...</p> <p>At the server level, you have "root /var/www/root". So basically, every location block will use this unless specifically overridden. This is good practice.</p> <p>You have then overridden it in the "wp" location block to "/var/www/wordpress". However, the php location block is still using the default.</p> <p>Now when you put in a request to "/wp/folder_a/file_a.php" which is physically located at "/var/www/wordpress/folder_a/file_a.php", the request hits the php location block and given the root folder active for that block goes to look for the file in "/var/www/root/folder_a/file_a.php". As a result, you get a "404 not found".</p> <p>You can change the server level root directive to "/var/www/wordpress" and remove the override in the wp location. This will solve that problem but php scripts under "/var/www/root" will no longer work. Not sure if you have any.</p> <p>If you need to run php under both "/var/www/root" and "/var/www/wordpress", you need to do this:</p> <pre><code>server { ... root /var/www/root; index index.php index.htm index.html; # Keep fastcgi directives together under location # so removed fastcgi_index # Put keepalive_timeout under 'http' section if possible location /wp/ { root /var/www/wordpress; # One appearance of 'index' under server block is sufficient location ~* \.php$ { try_files $uri =404; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } } location ~* \.php$ { try_files $uri =404; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } } </code></pre> <p>That is, nest a duplicate php location block under the wp location block. It will inherit the root directive for wp.</p> <p>To help keep things succint and ease edits etc, you can put the fastcgi directives into a separate file and include it in as needed.</p> <p>So in /path/fastcgi.params, you have:</p> <pre><code> fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; </code></pre> <p>Your conf can then be:</p> <pre><code>server { ... root /var/www/root; ... location /wp/ { root /var/www/wordpress; location ~* \.php$ { try_files $uri =404; include /path/fastcgi.params; } } location ~* \.php$ { try_files $uri =404; include /path/fastcgi.params; } } </code></pre> <p>In this way, if you need to edit any fastcgi param, you just edit it in the one place.</p> <p>PS. Updating your nginx will not solve this as it is not a version issue .. but update anyway!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload