Tips / Nginx

Why Nginx doesn’t support .htaccess files?

Nginx htaccess support may be the most common question for people that are running Apache and thinking about migrating to Nginx web server.

About nginx htaccess support

First of all, .htaccess files are a resource/performance hog, this is not good for website/server speed. Every time Apache handles a request, it first checks and processes any .htaccess file in the same directory as the file it is serving.  That’s quite normal, however, not all people know that Apache goes deep down through all the parent directories of the current one, and in every single one of them, it checks for .htaccess files.

For example: visitor is browsing and the document root is set to  /opt/www/websites/, this forces Apache to attempt to locate and process .htaccess files in all these directories:


This is the way Apache can handle dynamic rules without restarting/reloading his core, but as you see, it is a resource killer, specially for large websites with tons of traffic.

Another issue with dynamic .htaccess files, is the fact it is really insecure, as it is providing a way to alter server and website settings from a single file that is located inside the home directory of each website. This won’t happen if you have your rules inside Nginx configuration, as only root permission is granted to do so.

If you are a lazy developer you can still working with Apache and it’s .htaccess structure, however if you are serious about performance and security of your apps, now you know another reason why you should use Nginx Rewrite rules.At the end of the day, .htaccess provides a convenient shortcut for the lazy admin or developer, but also kills performance, makes configuration issues more difficult to track down, and opens yet another attack vector on your site.

Additional Resources

Popular search terms:


Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • den

    I think, lack of support for the .htaccess file is the huge minus for nginx.
    Erroneously impose its decision

    • naklov

      htaccess is a performance killer!
      Read this please:
      Test it if you don’t believe. Test it if you are not the “lazy developer” 🙂
      But if you are, then believe me. I have done many tests with nginx and Apache.
      Since performance is focused in nginx, there is no room for htaccess here!
      nginx is a performance monster. A well tuned nginx with php-fpm or even as reverse proxy, is love:)
      Jus create your config files (one time) and live it!

      • les

        Still its a big big minus

  • naklov

    Also nginx can reload configuration files without stopping. So there is no need for the performance killer dynamic configuration files. Everything done by htaccess can be done by nginx config files. ip deny, url rewrite, setting php admin values more and more and more:)

  • Tomas

    Please correct spelling in “This is the way Apache can handle dinamic” … Thanks

    • admin

      Done, thanks for reporting =)

  • NginxLover

    Nice article , also i want to know how to protect a path ( For Example admin panel ) with a firewall in Nginx Servers without using htaccess file