Nginx reverse proxy to apache won’t allow query strings in WordPress admin

apache-2.4nginxphp-fpmreverse-proxyWordpress

I'm running WordPress on a DigitalOcean droplet, it was working fine with an apache server but I put it behind an Nginx reverse proxy to serve static files better. The front-end website works but I'm having problems with the wp-admin area.

I can access the main wp-admin section without issue, (domain.com/wp-admin) and also any .php page (e.g. /wp-admin/upload.php)
however anytime I need to list something by post-type e.g.

/wp-admin/post-new.php?post_type=page

or

/wp-admin/edit.php?post_type=product

I get "post type not valid".

I'm assuming it's the nginx configuration, this is I think the only .conf file I edited at all when setting up nginx (it's in /etc/nginx/sites-available)

server {
listen 80;
listen 443;
server_name domain.com www.domain.com;
root /var/www/html;
index index.php index.htm index.html;

ssl on;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;

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

location ~ \.php$ {
    proxy_pass http://ipaddress:85$request_uri$query_string$is_args$args;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ /\. {
    deny all;
}
}

Could anyone help me find out what's going on here? Or at least where to look to debug this.

Edit:
found this in my apache access log:

10.15.0.2 - - [07/Dec/2017:17:15:05 +0000] "GET /wp-admin/edit.php?post_type=page?post_type=page HTTP/1.0" 500 3814 "www.domain.net/wp-admin/post.php?post=2&action=edit" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0"

Best Answer

I found the issue, it was a silly issue:

location ~ \.php$ {
    proxy_pass http://ipaddress:port$request_uri;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

instead of

location ~ \.php$ {
proxy_pass http://ipaddress:85$request_uri$query_string$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

}

The $is_args$args was leading to duplicated query strings