N
N
netherneon2011-03-18 15:04:19
Nginx
netherneon, 2011-03-18 15:04:19

Apache + nginx. Possible problems

At the moment there are a lot of sites on one server running on linux, apache 2.2.x mod_php, mysql. In connection with the increase in load, there is an idea to put the nginx frontend before this business. Tell me who did this, what are the pitfalls? Are there any chances that ajax's comet's .htaccess's or something else may fall off on some sites? Will site owners and developers notice any changes. I would appreciate any information, thanks in advance.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
Z
zizop, 2011-03-18
@zizop

There are two methods of this kind of migration.
1. Put Nginx in front of Apache. Here, in principle, everything is simple. Static (pictures, js, css, etc.) is distributed by Nginx, dynamics (php) is proxied to Apache. Pitfalls: correct division of content into static and dynamic, disabling logging for static, setting the correct caching time.
2. Abandon Apache completely in favor of Nginx. Potentially gives a greater performance boost. It is better to perform gradually, after the 1st method. Pitfalls:
you will have to rewrite .htaccess to Nginx directives. For popular engines like Joomla, WordPress, this has already been done, in other cases, you will have to smoke regexps. mod_php will most likely have to be replaced with php5-fpm, there seems to be nothing complicated here. Regarding comets, it will be necessary to puthttp_push_module for nginx . Everything, except for the last one, has recently passed, the performance has grown up a lot. The connection of memcached to nginx helped a lot in this, dynamic pages cached for guests moved into the category of statics.

A
admin4eg, 2011-03-18
@admin4eg

The devil himself is much more beautiful than it seems. the easiest option is to divide it into front-end and back-end,
I wrote instructions for myself for a long
time www.odmin4eg.ru/2008/nginx-na-ubuntu-prosto/
But its essence has not changed today, just tedious to download fresh nginx from the site , build it ( www.odmin4eg.ru/2009/nginx-na-ubuntu-eto-prosto-kompilyaciya/ )
and run it.
according to the same scheme, everything works for me so far perfectly, simply and reliably.
then a site appeared that was much harder than all the others, with the same scheme, it began to be processed by php5-fpm
and all the rest continued to work on apache as before
( www.odmin4eg.ru/2010/pereezzhaem-na-php5fpm/ )

U
unnamed, 2011-03-18
@unnamed

Everything will be fine, but there are features:
Out of the box - in the scripts and Apache logs there will be the ip address of the frontend and not the user, read for example here www.lexa.ru/srch/?text=rpaf§ion=6&sort1=rl
In Apache you need KeepAlive Off

G
gaelpa, 2011-03-18
@gaelpa

I saw the following pitfalls in PHP scripts:

  • Using $_SERVER['SERVER_NAME'], $_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'] will display apache backend data, i.e. nonsense can come out if these variables are used in the output
  • Using $_SERVER['REMOTE_HOST'] and $_SERVER['REMOTE_ADDR'] will return nginx frontend data

H
Horse, 2011-03-18
@Horse

I will offer another option. Nginx put next to the 81st port.
In this case, it will be easy to indicate that there is static, nothing needs to be proxyed, it works faster, there are no pitfalls at all (if, of course, the 81st port is open) )

W
Wott, 2011-03-18
@Wott

If you do not raise the cache, then everything has already been described. But I don’t really see the point in this - it’s better to switch to workers on apache.
If you raise it, then you need to carefully prescribe the keys for it and they depend on the scripts on the site and on the content. And in general, it is not always possible to effectively cache without changing the content or the scheme for obtaining it.
As noted, nginx handles static well, but if there is a lot of it, then it is more efficient
to combine scripts and styles into a common file
, move graphics to another domain
, optimize small things into sprites,
although of course these are all diagnoses over the phone.

P
pentarh, 2011-03-18
@pentarh

In the general case, there should be no problems if
1. Nginx will proxy dynamic requests to Apache
2. If Apache has mod_rpaf configured correctly You
can read about everything about this here Practical application of nginx to return static

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question