Issue
So I am trying to block certain web browsers (not that you need to know) and everyone says to add if ($http_user_agent ~* (Chrome) ) { return 403; }
I do all of that and when I run nginx -t it says this: nginx: [emerg] "if" directive is not allowed here in /etc/nginx/nginx.conf:64
Do you guys know why?
Solution
Nginx only allowed if
to be placed in a server
or location
block. if
should also not be in nginx.conf mostly, while it should be on /etc/nginx/sites-enabled/name.conf
or /etc/nginx/sites-available/name.conf
.
You also can't put a server
or location
block in nginx.conf because it would just give another error.
Answered By - FishyMine Answer Checked By - Timothy Miller (WPSolving Admin)