0

I have wordpress site running on apache and had to transfer it to nginx server.

I made pretty standard setup following instructions on nginx site (see my nginx config on the bottom). All works fine except in some cases wordpress adds extra slash on the end of admin-ajax calls. This happen in particular when edit properies in Visual Composer (when edit/add page), otherwise Visual Composer appears to work fine, see error here: https://imgur.com/SNJEYnI

From my investigation, this is caused by wrong variable definition for ajaxurl in wp-admin/admin-header.php

<script type="text/javascript">
...
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',

this resolves with extra trailing slash as

var ajaxurl = '/wp-admin/admin-ajax.php/',

After spending tones of time I manage to fix this by hacking wp-includes/link-template.php and trim last slash.

function admin_url( $path = '', $scheme = 'admin' ) {
    $url = get_admin_url( null, $path, $scheme );//patched fix
    $url = rtrim($url, '/');//patched fix
    return $url;//patched fix
    return get_admin_url( null, $path, $scheme );
}

That solves problem for now but I'm concerned that there is some issue with server configuration. Plus I do not want to keep on hacking site whenever new update comes. Any ideas how to solve this without hacking site will be appreciated!

nginx configuration for the website

server {
    server_name www.website.com;
    index index.php index.html index.htm;
    root /data/www/www.website.com/;


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




    location ~ \.php$ {
        fastcgi_index index.php;
        fastcgi_pass unix:/run/php/php5.6-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        include /etc/nginx/fastcgi_params;     
    }

    location /wp-admin/ {
        #no rewrite
    }


    location /quote/ {
            try_files $uri $uri/ /quote/index.php?$args;
    }
    location /quote-en/ {
            try_files $uri $uri/ /quote-en/index.php?$args;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.website.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.website.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.website.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name www.website.com;
    listen 80;
    return 404; # managed by Certbot
}

Your Answer

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

Browse other questions tagged or ask your own question.