HOW TO Solve Common NGINX Problems

Fist of all, I write this article to collect all the ways which I used for solved most common Nginx problems during VPS / Server setup process. That mean this post will continuing update until I move to another web server softwares for example: lighttpd, litespeed, ...
If you’re new or old to Nginx, you’ll facing with some problems, some of them can be solve easy with simple steps but we spend a lot time to research and fix it. Why? Did you know? The most frequent issue we see happens when someone attempts to just copy and paste a configuration snippet from some other guide. It’s the answer. Don’t follow the guides out there unless you can understand what they’re trying to do and can clean it up. You’ll solving almost common problems of Nginx.

Your Issue Isn’t Listed!

Yes, this post is not NGINX Problems Dictionary, you can’t find all at here. But don’t be shy, let’s commenting about your problem, maybe it’s can be solve soon with my knowledge or our audience.

HOW TO Solve Common NGINX Problems

The page isn’t redirecting properly or ERR_TOO_MANY_REDIRECTS

I faced this error after add Certbot SSL certificates to nginx configs. If I remove them or just only use normal connection (port 80), it’s work like charm. Everything seems working well with $ nginx -t but it’s still happened until I found the cause of this problem is Cloudflare SSL.
It sounds like you have it set to Flexible, so Cloudflare uses HTTP to reach your site, but your site redirects to HTTPS, and the cycle repeats.

Here are some methods to fix “The page isn’t redirecting properly” or “ERR_TOO_MANY_REDIRECTS” issue:

  • Change your Cloudflare SSL/TLS encryption mode is Full or Full (strict).
    Change your Cloudflare SSL/TLS encryption mode
    Change your Cloudflare SSL/TLS encryption mode
  • Remove the HTTPS redirects in your origin server. To ensure all requests between the browser and Cloudflare are encrypted, you can use an Always Use HTTPS page rule and that way avoid a redirect loop.

You can read more detail about this problem on Cloudflare’s Troubleshooting redirect loop errors.

400 Bad Request – Request Header Or Cookie Too Large

That’s strange error, someone thinks it’s browser error because restart your browser fixes this issue. If you face this error screen too frequently, your Nginx configuration has problem.

How to fix it

Try increasing the large_client_header_buffers directive in nginx

server {
...
large_client_header_buffers 4 16k;
... 
}

nginx: [emerg] “location” directive is not allowed here

The server directive has to be in the http directive. It should not be outside of it.

Let’s double check your nginx configuration to make sure it correctly.

Incase if you need detailed information, refer this.

403 Forbidden

Ahh, it’s very common error. Everybody has confused with this and how to fixed it. I’ve mentioned about 403 Forbidden on WordPress before, let’s read it before read on, maybe it’s help you fix this issue.

How to fix it

403 response headers are intentionally returned in many cases such as:

  • Nginx hasn’t permission to read / write to your website files
  • User tries to access a directory but autoindex is set to off.
Turn on autoindex
location /path/to/website/folder {
...
autoindex on;
... 
}
Set folder and files permission correctly or change owner of them

In Ubuntu, the default group and user for web server is www-data, re-check it and set it correctly. Before change it, you can find the information of nginx process:

$ ps -ef | grep nginx
www-data 14132 14130 0 16:06 ? 00:00:00 nginx: worker process

On Arch Linux, it’s http:http

3 thoughts on “HOW TO Solve Common NGINX Problems”

  1. I am getting a nginx.exe was unable to start correctly while shutdown my laptop in windows7 .pls help me sir…

Comments are closed.