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 (127.0.0.1) port (eg 81) – listen to the internal ip 127.0.0.1 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 (127.0.0.1:81), but pre-install the package libapache2-mod-rpaf, which will transfer to the apache not $ _SERVER [“REMOTE_ADDR”] = 127.0.0.1, 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:
bash:

deb http://ftp.ua.debian.org/debian-dou/ squeeze main
deb-src http://ftp.ua.debian.org/debian-dou/ squeeze main

Setting the key repository for nginx
bash:

gpg –keyserver subkeys.pgp.net –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 127.0.0.1:81:
bash:

nano /etc/apache2/ports.conf

bash:

NameVirtualHost 127.0.0.1:80
Listen 80

change on
bash:

NameVirtualHost 127.0.0.1:81
Listen 81

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

bash:

<VirtualHost *: 80>

to
bash:

<VirtualHost 127.0.0.1:81>

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

aptitude install libapache2-mod-rpaf

Now you can restart apache:
bash:

/etc/init.d/apache2 restart

Will install nginx-plus
bash:

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 127.0.0.1, rules are already in for him in the apache config and nginx.

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

server {
listen 80;
server_name 127.0.0.1;

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
/home/user/domains/127.0.0.1/www/$uri;
}

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

location / {
proxy_pass http://127.0.0.1:81/; # 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/127.0.0.1/www

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

bash:

<VirtualHost 127.0.0.1:81>

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

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

<Directory “/home/user/domains/127.0.0.1/www/cgi-bin /”>
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/127.0.0.1/log/error.log”
CustomLog “/home/user/domains/127.0.0.1/log/access.log” combined
LogLevel warn

</ VirtualHost>

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

/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.