Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a custom WP site that we are having to migrate from Apache to nginx and while most things are working ok, some big things are not.

For example on our custom plugin our url structure looks like this: ; PERMALINK is the field we use in the db to populate the cause information. In wordpress that is just a page with no content and a special theme page.

It works fine in apache, it doesn't work at all in nginx. We get a null page.

In the root directory on the apache site there is an .htaccess file that looks like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

So I tossed it into a converter and I get

if (-e $request_filename){
    set $rule_0 1;
if ($request_filename ~ "-l"){
    set $rule_0 1;
if (-d $request_filename){
    set $rule_0 1;
if ($rule_0 = "1"){
    #ignored: "-" thing used or unknown variable in regex/rew
rewrite ^/.*$ /index.php last;

But that doesn't really fix anything on the site. So without that in there, this is what my nginx config looks like:

server {
    listen 80;
    root /usr/share/nginx/html/;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?args;
    location ~ /\. { access_log off; log_not_found off; deny all; }
    location ~ ~$ { access_log off; log_not_found off; deny all; }
    location ~ \.php$ {
        try_files $uri $uri/ /index.php?args;
        include fastcgi_params;
        fastcgi_pass php5-fpm-sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
share|improve this question

Your try_files directives aren't passing arguments through correctly (you're missing the $ for $args. You also shouldn't need a try_files inside the .php block.

location / {
    try_files $uri $uri/ /index.php?$args;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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