I have a bunch of rewrite rules that I have to port from apache to nginx.
It's a rather painful process because I'm not able to see if my rewrite rules and "if" conditions are working as I want them to.
Apache did have debugging for its rewrite module. Whats can I do for nginx?
Enable
rewrite_log
:and set debug level in
error_log
directive:Enable debugging support, then set debug level in error_log.
Now you can tail the log and send your requests through. There's probably more detail than you want, but that can sometimes be a lifesaver.
Oh, and you should be aware that if is evil, in a location context at least...
Using logs and and built-in support for debugging is definitely the most reasonable way. If you are doing some quick routing debugging at early stages and want to interact through the browser/client only, using the return 4xx "text"; directive may also give you the answer you want with very little effort. For example,
The text in the returned webpage will tell you which
server
block your request triggered.Another good debug step is to check if your Nginx rules are being taken into account at all: