Saul Fontenot-Amedee

Web Development and Administration

Simple Nginx Rewrite Rules

Jun 162014

undefinedNginx is fast becoming the choice http server. In short it is faster and more secure than many of the other choices such as Apache. Creating rewrite rules for Nginx is an important part of any content strategy and it is not always as straight forward as Apache. This brief tutorial will demonstrate the basic setup for a rewrite rule.

You will need to create a folder and a file for your rewrite rules. Go to your root nginx folder usualy in /etc/nginx/.

mkdir rewrite rules
cd rewrite rules

touch yoursitename
vi yoursitename

Now that you are in the file you will need to write a rule. Let us pretend you want to create a redirect from /thisisit to .

rewrite ^/thisisit(.*)$$1 permanent;

In addition you will need to include your rewrite file in you configuration file. Here is the code you will need to add;

include /etc/nginx/yoursitename;

Next you will need to test your configuration with nginx -t and if it passes reload nginx -s reload . You rewrite rule should now be good to go if you need more complex rules you will need to know a little about regex.


New comment

comments powered by Disqus


Saul Fontenot Amedee a passionate dedicated web developer