Связка Nginx оптимизация и использование в роли обратного прокси (reverse proxy) FrontEnd, Apache BackEnd и вики-движок DokuWiki.
В этом случае nginx будет лишь посредником (прокси), стоящим перед Apache. Nginx будет служить для балансировки нагрузки и кэширования контента.
Apache будет работать на loopback интерфейсе localhost(127.0.0.1) и порту 81, nginx на всех интерфейсах используя порт 80.
# nano /etc/apache2/ports.conf
NameVirtualHost *:81
Listen 127.0.0.1:81
<IfModule mod_ssl.c>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
# nano /etc/apache2/sites-available/wiki.example.com
<VirtualHost *:81>
ServerName wiki.example.com
ServerAdmin webmaster@example.com
DirectoryIndex index.php
SetEnvIf X-Forwarded-Proto https HTTPS=on
ErrorLog ${APACHE_LOG_DIR}/wiki.example.com-error.log
CustomLog ${APACHE_LOG_DIR}/wiki.example.com-access.log combined
DocumentRoot /var/www/wikionline
<Directory /var/www/wikionline/>
Options FollowSymLinks MultiViews
AllowOverride All
Order deny,allow
allow from all
</Directory>
<LocationMatch "/(data|conf|bin|inc)/">
Order allow,deny
Deny from all
Satisfy All
</LocationMatch>
</VirtualHost>
# /etc/init.d/apache2 restart
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https;
# nano /etc/nginx/nginx.conf
user www-data;
# /etc/security/limits.conf
# nginx soft nproc 65535
# nginx hard nproc 65535
# nginx soft nofile 65535
# nginx hard nofile 65535
worker_rlimit_core 65535;
worker_rlimit_nofile 65535;
worker_processes 6; # не должно превышать количество ядер в процессоре
pid /var/run/nginx.pid;
events {
worker_connections 10000; # рассчитывается по формуле worker_rlimit_nofile/worker_processes
# multi_accept on;
}
http {
# Basic Settings
sendfile on;
client_max_body_size 10M;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging Settings
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Gzip Settings
gzip on;
gzip_disable "msie6";
##
# Virtual Host Configs
##
include /etc/nginx/proxy_params; # Host X-Real-IP X-Forwarded-For
server {
# default_server если не найдено имени виртуального хоста - nginx заблокирует доступ и
# не будет пересылать запрос Apache
listen 80 default_server;
server_name defaultwwwsite;
access_log /var/log/nginx/000-default-host.access.log;
deny all;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
# nano /etc/nginx/sites-available/wiki.example.com
server {
listen 80;
server_name wiki.example.com www.wiki.example.com;
root /var/www/mywiki/;
index index.php doku.php;
# Buffering
proxy_buffering on; # default on
proxy_max_temp_file_size 0; # 16096m default 1G
client_max_body_size 10240m; # 10m
client_body_buffer_size 128k;
error_log /var/log/nginx/example.com.info.error.log warn;
access_log /var/log/nginx/example.com.info.access.log;
location = /stat {
stub_status on;
access_log off;
allow 10.26.95.14;
allow 10.26.95.251;
deny all;
}
location ~ /(data|conf|bin|inc)/ { # Запретить доступ к каталогам data|conf|bin|inc
deny all;
}
location ~ /\. { # disabling access for files beginning with a point e.g. .htaccess, .git, .svn
deny all;
# access_log off;
# log_not_found off;
}
location / {
proxy_pass http://127.0.0.1:81;
include /etc/nginx/proxy_params; # Host X-Real-IP X-Forwarded-For
}
}
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
# /etc/init.d/nginx restart