If you are the administrator of the web server, then sooner or later the question of costs optimization of system resources consumed by apache. Specificallywe have a desire to give the files without processing them using apache. The solution is to install bundlesapache + nginx, nginx is where as the front-end forapache.
Both will work in conjunction with apache, nginx
Apache will listen to only one ip (127.0.0.1) port (for example 81)–listen to the internal ip of 127.0.0.1 tohave no desire to connect directly to apache, apachewill listen on port 81 for the reason that the 80 portwill now listen to nginx
If there is a request for a file with a resolution: (bmpjpg jpeg | | | pjpeg | ico | gif | png | css | doc | txt | js |docx | .RTF | ppt | pdf | swf)–you can change or add to the list, then a request to apache and nginx willnot immediately be given to the file that will saverequest processing time and system resources.
All other requests will be for redirecting the apache (127.0.0.1: 81), but first set the package libapache2-mod–rpaf, which will transmit to the apache is notthe $ _SERVER [“REMOTE_ADDR“] = 127.0.0.1 andreal client ip created the request.
Where to get a Debian repository for nginx nginx
The good guys (System administrators) are an Assembly of packages nxing and put all his effortsinto the repository:
bash:
-
deb http://ftp.ua.debian.org/debian-dou/ squeeze main
-
deb-src http://ftp.ua.debian.org/debian-dou/ squeeze main
The key for the repository setup 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 repositoriesyou can install nginx–plus, which unlike the usualpackage nginx going with additional modulesngx_loadavg_variables and ngx_addon’s_if_statment.patch. patch.
So get down to installing nginx + apache bundlesettings
The first thing I hope experience in configuringapache server is.
You will need to make apache listen to 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
So if you already have apache virtualhost, you mustlike images get to listen on 127.0.0.1: 81, replacing:
bash:
-
<VirtualHost *:80>
and
bash:
-
<VirtualHost 127.0.0.1:81>
Install libapache2-mod–rpaf apache to get the realclient ip, not 127.0.0.1
bash:
-
aptitude install libapache2-mod-rpaf
You can now restart apache:
bash:
-
/etc/init.d/apache2 restart
Install nginx-plus
bash:
-
aptitude install nginx-plus
Move on to configuring nginx hosts, which are stored in the directory:/etc/nginx/site-enabled/
Create a description for the host 127.0.0.1, pravivalready existing for the configs in apache 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 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root /var/www/nginx-default;
-
}
-
location / {
-
proxy_pass http://127.0.0.1:81/; # делаем переадресацию запросов на apache
-
proxy_redirect off;
-
proxy_set_header Host $host;
-
# Эти настройки необходимы, что бы из скриптов было видно реальные IP пользователя, а не фронт-части
-
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 apache virtualhostconfiguration/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 have noticed there is no big deal, just restart apache and nginx:
bash:
-
/etc/init.d/apache2 restart
-
/etc/init.d/nginx-plus restart
If you are not forgotten, the virtualhost change thesettings through the Control Panel, complexity ariseswhen you add or edit a virtualhost in bundlesbecause the default settings are designed to workonly with apache, but this topic I will discuss later in the example directadmin + nginx + apache.