How to fix 400 Bad request error in Nginx


Ok thans for suggesting me.


You could ask specifically.


@Rushikesh I am understanding your problem even when I installed my first server I failed like 5 times but I managed it in 6 time. Keep trying bro.

I can’t find any error in nginx block as of now.


I am mentioning last time…

  1. Rename wp-config.php to wp-config-deactivated.php (Temporarily. Wondering why? Because to eleminate Force HTTPS.)

using command …

cd /var/www/html
mv wp-config.php wp-config-deactivated.php
  1. Enter below commands

First delete existing block by typing

cd /etc/nginx/sites-available/
rm -rf *
cd /etc/nginx/sites-enabled/
rm -rf *

Go to sites-available directory of the nginx

cd /etc/nginx/sites-available/

Create a new NGINX server configuration block

nano jankaribook

It will open a editor kind of black screen, you need to paste below code using right click (not CTRL+V)

server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
client_max_body_size 0;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

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

location ~* \.php$ {
if ($uri !~ "^/uploads/") {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
location = /favicon.ico {
log_not_found off;
access_log off;

location = /robots.txt {
log_not_found off;
access_log off;
allow all;

location ~* .(css|gif|ico|jpeg|jpg|js|png)$ {
expires 30d;
log_not_found off;

How to save? Press CTRL+O and Enter key .

Next, test your code using

nginx -t

Then … type below command

ln -s /etc/nginx/sites-available/jankaribook /etc/nginx/sites-enabled/
sudo nginx -t
service nginx restart
systemctl restart php7.2-fpm.service
systemctl restart mysql
apt-get update

Next, make sure domain is pointed to your server IP

Check here:

Then only… attempt to install SSL of Let’s Encrypt. Else don’t to prevent site getting down and seeing connection refused error while accessing from HTTPS

add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-nginx
certbot --nginx -d -d


Then rename back to original wp-config.php, to make WordPress live with HTTPS

cd /var/www/html
mv wp-config-deactivated.php wp-config.php


I am waiting for your production ready guide dear.