Nginx + php-fpm VS Nginx as a reverse proxy for Apache

Solution 1:

Reverse proxying is slower and generally worse, however, some reasons to use it is to maintain (some) compatibility with .htaccess files (which you would have to write (and that isn't always practical) is you use a pure nginx setup) or if you require specific apache modules. (Some may argue that is you have these requirements, it is easier to just use apache.)

  1. PHP-FPM with nginx would be the preferred solution - you get the fast static file serving of nginx and good PHP performance without adding additional overhead, proxying, or the (typically) significant memory usage of apache.
  2. nginx+PHP-FPM is (typically) faster and uses less memory. Nginx + Apache + FastCGI/FPM will still serve static files fast, but will have additional overhead on the dynamic files (not as bad as mod_php, but worse than if you eliminate apache).
  3. You will need a bit of both - nginx would need to know how to deal with the paths (e.g. for serving static files, denying access to .htaccess, etc) and apache will need to know how to handle the files. In some cases, if your .htaccess file doesn't pertain to static files (so every request that needs rewriting is going to go to apache), then it may be acceptable to simply deny access to certain locations, and have apache do the rest via .htaccess - it doesn't seem ideal, will cost a bit in performance, and its reliability is questionable - but it could work on a simple setup).

If you can, go with the straight nginx+PHP-FPM setup. If you can't, while there may be some merits to reverse-proxying, think through the repercussions, especially if you are dependent on .htaccess files.

Solution 2:

I would say that it's the other way around: cutting Apache out of the mix will increase performance. You'd keep Apache around if you like some of the other modules Apache provides, or if you have some external reason to keep using Apache for your dynamic content.

It should be fine to let Apache handle the rewrites, so long as you don't do anything to accesses of your static content. But make sure to have an exclude for .ht* in your nginx conf: don't want to accidentally serve those particular static files out to the general public.