Nginx + WordPress : 414 Request-URI Too Long

nginxWordpress

I use Nginx with php-fpm on my server to run my WordPress blog.

When someone share my website on Facebook, some parameters are added by Facebook and the URL looks like :

https://jp.rlauzier.com/2013/07/les-courriels-et-la-securite-quelques-notions-a-savoir/?fb_action_ids=268110373331078&fb_action_types=og.likes&fb_source=other_multiline&action_object_map=%7B%22268110373331078%22%3A434166526690497%7D&action_type_map=%7B%22268110373331078%22%3A%22og.likes%22%7D&action_ref_map=%5B%5D

I checked my logs and I have a "414 Request-URI Too Long" with this request. I try to add large_client_header_buffers in my Nginx config file but without result.

However, if you only use the normal URL (https://jp.rlauzier.com/2013/07/les-courriels-et-la-securite-quelques-notions-a-savoir/), everything work correctly.

Here's my configuration file:

server {
    listen          443;
    server_name     jp.rlauzier.com;

    ssl on;
    ssl_certificate         /etc/nginx/ssl/jp.rlauzier.com.crt;
    ssl_certificate_key     /etc/nginx/ssl/jp.rlauzier.com.key;

    include /var/www/jp.rlauzier.com/public_html/nginx.conf;

    location / {
            root   /var/www/jp.rlauzier.com/public_html/;
            index  index.php index.html index.htm;

            if ($request_uri ~* \.(ico|css|js|gif|jpe?g|png)$) {
                    expires max;
                    break;
            }

            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            root           /var/www/jp.rlauzier.com/public_html/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
    }

    location ~ /(\.|wp-config.php|nginx.conf|readme.html|license.txt) {
            return 404;
    }
}

server {
    listen       80;
    server_name  jp.rlauzier.com rlauzier.com;

    rewrite     ^ https://jp.rlauzier.com$request_uri? permanent;
}

Best Answer

From somewhere on the internet:

Most likely you are trying to configure client_header_buffer_size/large_client_header_buffers in a pure virtual server{}. This won't work as request headers parsing happens before Host header is known (and virtual server isselected), hence parseing happens in a context of the default server for a listen socket.

You have to configure client_header_buffer_size/large_client_header_buffers in a default server (or at http level).