1

I am trying to figure out on how to migrate from Apache to nginx, keeping rewrite rules flexible to change for developers. This is our current setup:

  • We have a .htaccess file in the root folder of the project (and in some subfolders as well)
  • In this .htaccess file, the developers can define rewrites for pretty permalinks to specific scripts (we don't use a "global" index.php file)
  • This .htaccess file is included in our Git repo, so adding/changing rewrites does not require the developer to change the server configuration (which he has no permissions to)

As far as I learned already, there is no such thing as a per-directory .htaccess equivalent with nginx. So how can we possibly solve this? Do we have to use a "global" index.php file to resolve the rewrites? That would probably decrease the overall performance significantly.

P.S. As you might have noticed, I never used nginx before.

5
  • Having a front controller really does not have a significant performance penalty. It's basically just an extra switch call in your application rather than a bunch of regexes in the web server. Which, come to think of it, might even perform better... Oct 10, 2014 at 16:31
  • I would say that looping over a PHP array with regexes (and eventually conditions) would be less performant than having it done by a server configuration file.
    – 2ndkauboy
    Oct 10, 2014 at 16:42
  • 1
    Sounds like premature optimization to me. A front controller is just cleaner all around; there's little reason not to have one. Oct 10, 2014 at 16:45
  • Do really need to switch from Apache to Nginx? From your use-case Apache might just be the better tool for the job. Oct 10, 2014 at 16:57
  • The problem with our website is that once a year, we have a week, where traffic will be 10x as much as on a regular basis. And nginx offers a lot of options to solve such high loads. So we really want to try out, how nginx will handle those high loads. I don't think that out setup is very unique.
    – 2ndkauboy
    Oct 10, 2014 at 17:18

1 Answer 1

0

OK, so firstly I think you should consider carefully whether nginx will really help you with your performance problem (per your comment), and test that in a development environment before worrying about how your deployment will work.

It is true that nginx is faster, and that it's multi-threaded architecture helps deal with high loads, but yours would be an extraordinarily unusual PHP site if the part of your operation you are looking to speed up accounts for more than one or two percent of the total delays. Your bottleneck will almost certainly be in your database and PHP execution.

You should probably look first at PHP compilation caching (eg APC), a front end proxy (eg varnish or squid), internal caching within your application (is this wordpress? there's some good caching modules there). Handing off delivery of static files only to nginx might be agood idea, but it's probably better to look at using either your own proxies, or a Content Distribution Network for that content anyway.

If you do decide to proceed though, some tools come to mind, albeit they are fairly heavy weight tools. You could use continuous integration and configuration management tools (eg Jenkins and Puppet, or equivalents) to deploy your configuration from a version control repository to your server whenever its checked into the appropriate branch. This is a lot of infrastructure complexity to learn about and build though, and without a good deal knowledge, skill and care, you might as well be just giving your developers root access anyway. Apache's system of delegation through .htaccess has been developed over many years, and you're not going to replicate it's security in a hurry.

Go back and check your assumptions with a profiling tool about how much of a performance issue your regex handling is. I've used mostly Xdebug, but there are other good alternatives.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .