Howto install วิธีติดตั้ง Nginx สำหรับ Directadmin
โดย http://www.ireallyhost.com- wget http://nginx.org/download/nginx-1.3.9.tar.gz
- tar xvfz nginx-1.3.9.tar.gz
- ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
- make
- make install
- vi /usr/local/nginx/conf/nginx.conf
user apache apache;
worker_processes 4;
worker_rlimit_nofile 8192;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server_tokens off;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error_log debug;
server_names_hash_bucket_size 64;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 30;
gzip on;
gzip_comp_level 9;
gzip_proxied any;
proxy_buffering on;
proxy_cache_path /usr/local/nginx/proxy_temp levels=1:2 keys_zone=one:15m inactive=7d max_size=1000m;
proxy_buffer_size 16k;
proxy_buffers 100 8k;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
server {
listen __IP__:85 default rcvbuf=8192 sndbuf=16384 backlog=32000; # Real IP here
server_name domain.name _ ; # "_" is for handle all hosts that are not described by server_name
charset off;
access_log /var/log/nginx/nginx_host_general.access.log main;
location / {
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_pass http://__IP__; # Real IP here และไม่มี / ปิดท้าย
client_max_body_size 16m;
client_body_buffer_size 128k;
proxy_buffering on;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 120;
proxy_buffer_size 16k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location ~* ^/(phpmyadmin|webmail|squirrelmail|uebimiau|roundcube)/.+\.(jpg|jpeg|gif|png|ico|css|zip|tar|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js|wmv|avi|cur|swf|mp3|wma|htc|cur)$ {
root /var/www/html/;
expires 30d;
access_log off;
}
location ~* ^/(stats)/.+\.(jpg|jpeg|gif|png|html|htm)$ {
root /var/www/html/;
access_log off;
}
location ~* ^/(mrtg|imrtg)/.+\.(jpg|jpeg|gif|png|html|htm)$ {
root /var/www/html/;
access_log off;
}
location /nginx_status {
stub_status on;
access_log off;
allow __IP__; # Real IP here
allow 127.0.0.1;
deny all;
}
}
include /usr/local/nginx/etc/*.conf;
}
- mkdir /var/log/nginx
- touch access.log
- touch error_log
- touch nginx_host_general.access.log
- vi /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
- chmod +x /etc/init.d/nginx
- /sbin/chkconfig nginx on
- service nginx restart
Install Mode mod_rpaf (เพื่อแก้ปัญหา เก็บ IP ใน Log ได้ถูกต้อง)
- wget http://www.stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
- tar xzf mod_rpaf-0.6.tar.gz
- cd mod_rpaf-0.6
- apxs -cia mod_rpaf-2.0.c
- vi /etc/httpd/conf/extra/httpd-includes.conf
RPAFenable On
RPAFsethostname On
RPAFproxy_ips __IP__(แก้ไขเป็น IP เซิร์ฟเวอร์)
RPAFheader X-Forwarded-For
Forward Port
- iptables -t nat -A PREROUTING -i __INTERFACE__ -p tcp --dport 80 -j REDIRECT --to-port 85
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 85
-
/etc/init.d/iptables save
Reference
- http://articles.slicehost.com/2009/2/2/centos-adding-an-nginx-init-script
- http://www.ireallyhost.com/kb/7/
- http://www.thaihosttalk.com/showthread.php/67435-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87-config-NGINX-%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%A2%E0%B8%B8%E0%B9%88%E0%B8%87%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3%E0%B8%81%E0%B8%B1%E0%B8%9A-DA-%E0%B9%80%E0%B8%A5%E0%B8%A2-%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87-Run-Cron-%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%81%E0%B8%81%E0%B9%89-unlimit-%E0%B8%A3%E0%B8%B9%E0%B8%9B%E0%B8%82%E0%B8%B6%E0%B9%89%E0%B8%99%E0%B8%97%E0%B8%B8%E0%B8%81%E0%B9%80%E0%B8%A7%E0%B9%87%E0%B8%9A
** บทความนี้มีลิขสิทธิ์ ไม่อนุญาติให้คัดลอก ทำซ้ำ ดัดแปลงก่อนได้รับอนุญาต **
โปรดระบุแหล่งที่มา บริษัท เอ็กซ์ตร้า คอร์ปอเรชั่น จำกัด / https://www.ireallyhost.com