Setting ligament apache + nginx

If you web-server administrator then sooner or later the question of cost optimization of system resources consumed by apache. Specifically we have the desire to serve the files without processing them using apache. The solution is to install bundle apache + nginx, nginx is where as a front-end to apache.

How will work in conjunction with nginx apache

Apache will listen to only one ip ( port (eg 81) – listen to the internal ip in order to anybody nebylo desire and the ability to connect directly to the apache, 81 port will listen apache for the reason that 80 port will now listen to nginx
If there is a request to a file with a resolution of: (bmp | jpg | jpeg | pjpeg | gif | ico | png | css | doc | txt | js | docx | rtf | ppt | pdf | swf) – You can change or add to the list, then the request to apache will not be made immediately and nginx will give the file, which saves query processing time and system resources.
All other requests we are forwarding to apache (, but pre-install the package libapache2-mod-rpaf, which will transfer to the apache not $ _SERVER [“REMOTE_ADDR”] =, and the real ip of the client making the request .

Where can I get nginx to Debian – repository nginx
The good guys (system administrators) are reassembly nxing and spread all his works to the repository:

deb squeeze main
deb-src squeeze main

Setting the key repository for nginx

gpg –keyserver –recv-keys 0A3D4789
gpg –armor –export 0A3D4789 | apt-key add –

After updating the list of packages in the repositories you can install nginx-plus, which is in contrast to the usual package nginx going with additional modules and ngx_loadavg_variables.patch ngx_addon’s_if_statment.patch.

So begin the installation settings ligament nginx + apache
The first thing I hope the experience in setting up a server on apache is.

Must be made to listen to apache

nano /etc/apache2/ports.conf


Listen 80

change on

Listen 81

Also, if you are already a virtualhost apache, you must make a similar way to listen to, replacing:


<VirtualHost *: 80>



Will install libapache2-mod-rpaf apache to get a real ip client, not

aptitude install libapache2-mod-rpaf

Now you can restart apache:

/etc/init.d/apache2 restart

Will install nginx-plus

aptitude install nginx-plus

We proceed to configure hosts nginx, which are stored in the directory: / etc / nginx / site-enabled /

Let’s create a description for the host, rules are already in for him in the apache config and nginx.

Config / etc / nginx / sites-enabled / default:

server {
listen 80;

access_log /var/log/nginx/localhost.access.log;

location ~ * ^. + \. (bmp | jpg | jpeg | pjpeg | gif | ico | png | css | doc | txt | js | docx | rtf | ppt | pdf | swf | zip | rar | gz) $ {
expires 10d;
log_not_found on;
try_files $ uri

error_page 500502503504 /50x.html;
location = /50x.html {
root / var / www / nginx-default;

location / {
proxy_pass; # Do redirects requests to apache
proxy_redirect off;

proxy_set_header Host $ host;
# These settings are required to be of the scripts be seen real IP user, not the front part
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;

client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;


I think it is clear that our site is in the directory: /home/user/domains/

Now, edit the settings in the virtualhost apache / etc / apache2 / sites-enabled / 000-default



DocumentRoot /home/user/domains/
ServerAlias ​​localhost
ServerName www.localhost
ScriptAlias ​​/ cgi-bin / /home/user/domains/

<Directory “/home/user/domains/”>
AllowOverride All
Order Deny, Allow
Allow from all
Options All
</ Directory>

<Directory “/home/user/domains/ /”>
AllowOverride None
Options + ExecCGI -MultiViews + SymLinksIfOwnerMatch
Order allow, deny
Allow from all
</ Directory>

<IfModule dir_module>
DirectoryIndex index.php index.html index.cgi
</ IfModule>

#SuexecUserGroup Valualit valualit
ErrorLog “/home/user/domains/”
CustomLog “/home/user/domains/” combined
LogLevel warn

</ VirtualHost>

As you may have noticed nothing complicated about it, you just restart apache and nginx:

/etc/init.d/apache2 restart
/etc/init.d/nginx-plus restart

If you have been around virtualhost, most importantly do not forget to change the settings when working through the control panel complexity arises when adding or editing virtualhost in bundles because the default settings are designed to work only with apache, but this topic I will discuss later in the example directadmin + apache + nginx.