Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run (and check) Nginx rewrite rules without running the whole web server?

I want to get as close as I can to "unit testing" Nginx rewrite rules. How close can one get to doing this? Is there a way to run the request rewriting module without running the entire web server? Can I embed the Nginx server in a process running Ruby or Python or, if I have to, Java? What tricks can you think of?

like image 438
J. B. Rainsberger Avatar asked Mar 14 '23 09:03

J. B. Rainsberger


1 Answers

  1. Put your rewrite rules in an include file.

  2. Create Nginx configuration just for testing that pulls in the rewrite include file.

  3. Using the -c and possibly the -g flags, Run nginx as a user. Since you can run it on an alternate port, this won't conflict with a web server running on port 80.

  4. Have your automated testing run tests against this "test server".

  5. Shut down the nginx test server.

like image 194
Mark Stosberg Avatar answered Apr 08 '23 16:04

Mark Stosberg