K
K
Kirill Kazakov2015-04-20 14:42:50
PHP
Kirill Kazakov, 2015-04-20 14:42:50

Nginx + php5-fpm VS Nginx + Apache; What to choose?

Does Nginx + php5-fpm really benefit in terms of performance?
Is it possible to screw .htaccess Nginx + php5-fpm ?
Should I switch to Nginx + php5-fpm ?
Now there is nginx + apache on virtual machines on a dedicated server. All on Centos + openvz.
There are many different projects going on.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Filimonov, 2015-04-20
@mausspb

Does Nginx + php5-fpm really benefit in terms of performance?

They have a different architecture: nginx can serve more requests per unit of time with less memory consumption. So in theory it should be: yes, strongly.
You can do everything that .htaccess can do in the nginx config, but you can’t fasten it.
Should I switch to Nginx + php5-fpm ?
Now there is nginx + apache on virtual machines on a dedicated server. All on Centos + openvz.
There are many different projects going on.

What for? If you're asking these questions, you're good now.
The scheme with nginx is prettier, lighter, easier to set up. I've been using nginx+gunicorn for several years now (this is a python wsgi server, a layer between the application and the web server), there is no need for apache. But if everything is OK, you do not need to go. Also, if you need to work with typical projects that need .htaccess, but you didn’t write it, it will be sad: I constantly cry bloody tears if such a task arises, because. you need to rewrite all these .htaccess.

H
hell, 2015-04-21
@hell

On the first point:
It would be more correct to test on the actual hardware and in the current configuration. In addition, the answer to your question will also depend on your ability to adjust kernel parameters. On virtual machines, you may not have such an opportunity.
A year and a half ago I did such tests for my server.
Three options were tested - nginx+php-fpm, nginx+apache+mod_php, nginx+nginx+php-fpm. test results on combat sites showed:
with the correct configuration of apache - nginx + php-fpm - the least productive solution
nginx + apache + mod_php and nginx + nginx + php-fpm withstand approximately the same load, but the second solution is slightly less reliable (that is, just a little - on average, for 1000 siege attacks on the combat server, php-fpm crashed 7 times, and Apache - times 2)
The software has changed since then, your hardware is obviously different (the one I tested on burned out), I had debian without virtual machines, you have Centos, so the actual test results in your case may be different.
On the second - let me quote myself - "with the correct configuration of apache". Proper tuning of Apache for performance includes a complete rejection of .htaccess. Some are transferred to nginx, some are transferred directly to the configs of a specific web server. Well, in general, a lot, a lot, a lot of things are thrown out of Apache. It must be remembered that the rewriting rules in nginx are different from those in Apache - there were a couple of correct (especially with comments) articles on Habré, and there are more than enough good examples on the nginx website itself.
On the third - if you run tests and make sure that everything is fine with the reliability of the nginx + nginx + php-fpm bundle on your sites, I would switch.
Let me explain the meaning of this connection:
external nginx gives statics, zips on the fly, partially rewrites requests, and also proxies requests to php to internal nginx. In addition, if necessary and possible, it can cache some requests. The external nginx has keepalive_timeout set to a sufficiently large value (that is, it is also worth picking up).
Internal nginx is set to keepalive_timeout=0, and works with php-fpm.
A great bonus of such a bundle is the ability to cache pages with the simultaneous, simple and naive disabling of caching of the interactive part (that is, for example, you cache the entire site except for the comment block and the block of some kind of cool chips that are displayed randomly).
The downside is the fundamental differences in the logic of rewriting on nginx and in apache. In fact, if you spend 2-3 working days once to sort out these differences, then everything will be easier.

S
Sergey, 2015-04-20
Protko @Fesor

1) .htaccess is not needed, usually you have a default server config which does not differ much from project to project. You can do automatic vhost creation within a single nginx configuration.
2) Apache in 90% of cases is not needed if you do not use some very specific modules.
Conclusion - why add an extra layer?

P
Puma Thailand, 2015-04-20
@opium

1) In terms of performance, php loses because mod_php is the fastest version of php. In memory consumption, it can win at times.
2) no of course
3) worth
4)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question