给DirectAdmin面板增加nginx前端
装好Directadmin面板之后,假设高并发流量进来,apache跑起来还是很吃力的.所以在前面装个nginx是很有必要的.但是因为我对directadmin的api还不熟悉.对它绑定域名这块没有较好的方法.不能实现动静分离.装上nginx也只是起到一个缓存和keepalive的作用.nginx监听80端口.apache监听81端口.安装还是很简单的.我只在CentOS环境中测试.在Debian平台上没有测试.大家自己测试一下呗.OK.step by step...
第一步,安装nginx.这里我没有安装pcre库.伪静态还是沿用apache的.htaccess.cd /usr/local/src/
wget http://nginx.org/download/nginx-0.7.65.tar.gz
tar -zxf nginx-0.7.65.tar.gz
cd nginx-0.7.65
./configure --user=apache --group=apache --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx--conf-path=/etc/nginx/conf/nginx.conf --pid-path=/var/log/nginx/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx_client --http-proxy-temp-path=/tmp/nginx_proxy --http-fastcgi-temp-path=/tmp/nginx_fastcgi --with-http_stub_status_module
make
make install添加启动脚本#! /bin/sh
ulimit -n 65535
# Description: Startup script for nginx
# chkconfig: 2345 55 25PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/sbin/$NAME
CONFIGFILE=/etc/nginx/conf/nginx.conf
PIDFILE=/var/log/nginx/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAMEset -e
[ -x "$DAEMON" ] || exit 0do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}waitforexit() {
count=${2:-30}
while [ 0$count -gt 0 ]
do
PIDS=`ps -C$NAME --no-heading e | grep $DAEMON` || break
PIDS=`echo "$PIDS" | awk '{print $1}' | tr '\n' ' '`
echo Remaining processes: $PIDS
do_stop
sleep 2
count=`expr $count - 1`
done
if [ 0$count -eq 0 ];
then
echo Remaining processes: $PIDS
return 1
fi
return 0
}do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
waitforexit "nginx" 20
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esacexit 0嗯嗯.这个脚本很熟悉吧,呵呵.记得赋予执行权限,chmod 755 /etc/init.d/nginx 接着设置nginx.conf.mv /etc/nginx/conf/nginx.conf /etc/nginx/conf/nginx.conf.bak
mkdir /etc/nginx/conf/ips
vim /etc/nginx/conf/nginx.conf输入以下内容worker_processes 4;
worker_rlimit_nofile 51200;
events {
worker_connections 51200;
use epoll;
}
error_log /var/log/nginx/error.log info;
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120;
gzip on;
gzip_http_version 1.0;
gzip_min_length 1100;
gzip_comp_level 3;
gzip_buffers 4 32k;
gzip_types text/plain text/xml text/css application/x-javascript application/xml application/xml+rss text/javascript application/atom+xml;
ignore_invalid_headers on;
connection_pool_size 256;
request_pool_size 32k;
server_names_hash_max_size 2048;
server_names_hash_bucket_size 256;
output_buffers 4 64k;
postpone_output 1460;
#open_file_cache max=1000 inactive=300s;
#open_file_cache_valid 600s;
#open_file_cache_min_uses 2;
#open_file_cache_errors off;
client_max_body_size 100m;
client_body_buffer_size 256k;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
include "/etc/nginx/conf/ips/*.conf";
}在/etc/nginx/conf/ips路径下.添加监听的IP地址的虚拟主机配置,有多个IP.就添加多几个主机配置,以192.168.2.1为例:server {
listen 192.168.2.1:80;
server_name _;
access_log off;
error_page 400 401 402 403 404 405 406 407 408 409 500 501 502 503 504 @backend;
location @backend {
internal;
proxy_connect_timeout 30s;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_path /dev/shm/proxy_temp;
proxy_redirect http://$host:81 http://$host;
proxy_redirect http://www.$host:81 http://$host;
proxy_pass http://192.168.2.1:81;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_connect_timeout 30s;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_path /dev/shm/proxy_temp;
proxy_redirect http://$host:81 http://$host;
proxy_redirect http://www.$host:81 http://$host;
proxy_pass http://192.168.2.1:81;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}上例中的error_page都转发到后端.第二步,给apache安装rpaf模块cd /usr/local/src/
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
tar -zxf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
/usr/sbin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c安装完了之后.编辑/etc/httpd/conf/httpd.conf文件.添加以下内容:LoadModule rpaf_module /usr/lib/apache/mod_rpaf-2.0.so
#Mod_rpaf settings
RPAFenable On
RPAFproxy_ips 127.0.0.1
RPAFsethostname On
RPAFheader X-Forwarded-For改成你自己的监听IP第三步,修改DirectAdmin设置这一步要做的是修改默认apache的监听端口.需要对apache的配置有一定的认识.进入/usr/local/directadmin/data/templates目录.可以看到很多设置文件.这些文件都是默认建立账户或绑定域名时.directadmin会根据这些模板生成相关程序的参数配置文件.主要要修改的文件包括: httpd.conf ips_virtual_host.conf virtual_host2_sub.conf virtual_host.conf virtual_host_sub.conf httpd.conf redirect_virtual_host.conf virtual_host2.conf 在这些文件中,搜索"80",改成"81".这一步没什么好说的了.细心一点改.httpd.confPort 81
Listen 81
Listen 443ips_virtual_host.conf virtual_host2_sub.conf virtual_host.conf virtual_host_sub.conf httpd.conf redirect_virtual_host.conf virtual_host2.conf<VirtualHost |IP|:81>此外还要修改已绑定域名的配置文件.位于/etc/httpd/conf /usr/local/directadmin/data/users/ 两处目录.进入以上路径后可以使用以下命令查找端口.grep 80 . -r端口还是改成"81".然后还是细心一点.接着重启一下nginx和httpd.最后再修改一个地方就完事了.cd /etc/httpd/conf/
vim httpd.conf注释掉Include /etc/httpd/conf/ips.conf,再在下面把你所监听的IP都添加上去:NameVirtualHost ip:81
NameVirtualHost ip:443tip:1.建议关闭apache的Deflate模块.直接在/etc/httpd/conf/httpd.conf中注释掉Deflate模块那一段.在第165行.
2.假设想要在httpd重启的时候一并重启nginx.可以在/etc/init.d/httpd中自行添加命令.http://icodex.org/wp-content/uploads/2010/05/httpd-init.png
页:
[1]