给DirectAdmin面板增加nginx前端

[不指定 2012/11/30 00:24 | by Totti ]
| |
装好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 25
PATH=/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/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
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
sleep 1
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 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  2;
worker_rlimit_nofile  65535;
events {
worker_connections  65535;
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 65;
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;
client_header_timeout  3m;
client_body_timeout 3m;
send_timeout     3m;
connection_pool_size  256;
server_names_hash_max_size 2048;
server_names_hash_bucket_size 256;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
request_pool_size  32k;
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;
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;
client_max_body_size    100m;
client_body_buffer_size 128k;
proxy_send_timeout   300;
proxy_read_timeout   300;
proxy_buffer_size    32k;
proxy_buffers     256 32k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 64k;
proxy_connect_timeout 30s;
proxy_pass http://192.168.2.1:81;
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 / {
client_max_body_size    100m;
client_body_buffer_size 128k;
proxy_send_timeout   300;
proxy_read_timeout   300;
proxy_buffer_size    32k;
proxy_buffers     256 32k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 64k;
proxy_connect_timeout 30s;
proxy_pass http://192.168.2.1:81/;
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 [your_ips]
RPAFsethostname On
RPAFheader X-Forwarded-For
[your_ips]改成你自己的监听IP

第三步,修改DirectAdmin设置

这一步要做的是修改默认apache的监听端口.需要对apache的配置有一定的认识.进入/usr/local/directadmin/data /templates目录.可以看到很多设置文件.这些文件都是默认建立账户或绑定域名时.directadmin会根据这些模板生成相关程序的参数配置 文件.

主要要修改的文件包括: 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".这一步没什么好说的了.细心一点改.

此外还要修改已绑定域名的配置文件.位于/etc/httpd/conf /usr/local/directadmin/data/users/  两处目录.进入以上路径后可以使用以下命令查找端口.

grep 80 . -r
端口还是改成"81".然后还是细心一点.最后重启一下nginx和httpd.完事了...

tip:1.建议关闭apache的Deflate模块.直 接在/etc/httpd/conf/httpd.conf中注释掉Deflate模块那一段.在第165行.
2.如果想要在httpd重启的时候一并重启nginx.可以在/etc/init.d/httpd中自行添加命令.
收集 | 评论(0) | 引用(0) | 阅读(6060)
发表评论
昵称

网址

电邮
打开HTML 打开UBB 表情 打开表情 隐藏 记住我 [注册]