How can I use an .htaccess file in Nginx? How can I use an .htaccess file in Nginx? nginx nginx

How can I use an .htaccess file in Nginx?


Nginx doesn't support .htaccess (see here: "You can’t do this. You shouldn’t. If you need .htaccess, you’re probably doing it wrong.").

You've two choices (as I know):


Disclaimer: I am the author of htaccess for nginx, which is now open source software.

Over the past years, I created a plugin which implements htaccess behaviour into nginx, especially things like RewriteRule, Allow and Deny, which can be crucial for web security. The plugin is used in my own productive environments without a problem.

I totally share the point of efficiency and speed in nginx, and why they didn't implement htaccess.However, think about it. You cannot make it worse if you're using nginx plus htaccess. You still keep the great performance of nginx, plus you can drive your legacy appliances effortlessly on one webserver.


This is not supported officially in nginx. If you need this kind of functionality you will need to use Apache or some other http server which supports it.

That said, the official nginx reasoning is flawed because it conflates what users want to do with the way it is done. For example, nginx could easily check the directories only every 10 seconds / minute or so, or it could use inotify and similar mechanisms. This would avoid the need to check it on every request... But knowing that doesn't help you. :)

You could get around this limitation by writing a script that would wait for nginx config files to appear and then copy them to /etc/nginx/conf.d/. However there might be some security implications - as there is no native support for .htaccess in nginx, there is also no support for limiting allowed configuration directives in config files. YMMV.