How to fix 400 Bad request error in Nginx


(Rushikesh Sonawane ) #84

Ok thans for suggesting me.


#85

You could ask specifically.


#86

@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.


#87

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;
server_name .jankaribook.com;
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: https://dnschecker.org/#A/jankaribook.com

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 jankaribook.com -d www.jankaribook.com

Source: https://gulshankumar.net/install-wordpress-with-lemp-on-ubuntu-18-04/

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

(Gopal) #88

Your guide looks good!

Without any good guide VPS is not recommended for newbie’s.


(Batman of the forum) #89

I am waiting for your production ready guide dear.


(Gopal) #90

Yes! guide is on the way and right now I am performing testing of guide so that it will be error free.

Newbie can install WordPress so easily also ready for production use.