0

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: domain.com/causes-details/PERMALINK ; 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]
</IfModule>

So I tossed it into a converter http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ 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/domain.com;
    index index.php index.html index.htm;
    server_name domain.com www.domain.com;
    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;
    }
}
0

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

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.