wget http://nginx.org/download/nginx-1.5.13.tar.gz
[root@localhost nginx-0.8.37]# make
[root@localhost nginx-0.8.37]# make install
디렉토리 생성
[root@localhost nginx-0.8.37]# mkdir /usr/local/nginx/conf
서비스 데몬 작성
[root@localhost nginx-0.8.37]# vi /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: – 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/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/nginx/sbin/nginx”
prog=$(basename $nginx)
NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -
options=$nginx -V 2>&1 | grep 'configure arguments:'
for opt in $options; do
if [ echo $opt | grep '.*-temp-path'
]; then
value=echo $opt | cut -d "=" -f 2
if [ ! -d “$value” ]; then
# echo “creating” $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
sleep 1
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
[root@localhost nginx-0.8.37]# chmod 755 /etc/rc.d/init.d/nginx
[root@localhost nginx-0.8.37]# vi /usr/local/nginx/conf/nginx.conf
#———————————————————————–#
user nobody;
pid log/nginx.pid;
error_log log/error.log;
#———————————————————————–#
worker_processes 2;
events {
worker_connections 1024;
# use kqueue; # FreeBSD – kqueue
} # Linux – epoll
# Syntax: use [ kqueue | rtsig | epoll | /dev/poll | select | poll | eventport ]
#———————————————————————–#
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”‘;
access_log off;
## Size Limits
client_body_buffer_size 1024m;
client_max_body_size 1024m;
client_header_buffer_size 1024m;
large_client_header_buffers 1 1024m;
## Timeouts
send_timeout 5;
keepalive_timeout 5 5;
client_body_timeout 5;
client_header_timeout 5;
## General Options
sendfile on;
server_tokens off;
recursive_error_pages on;
ignore_invalid_headers on;
server_name_in_redirect off;
limit_zone gulag $binary_remote_addr 1m;
## TCP options
tcp_nodelay on;
tcp_nopush on;
## Compression
gzip on;
gzip_static on;
gzip_buffers 16 8k;
gzip_comp_level 9;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/css image/x-icon image/bmp image/png application/x-javascript image/gif;
gzip_vary on;
# Virtualhost
server {
listen 80;
server_name nginx1.xinet.kr;
root /home/xinet/html/;
index index.html index.htm;
charset utf-8;
location ~* ^.*\.(ico|css|js|gif|jp?g|png|svg|bmp)\?[0-9]+$ {
access_log off;
expires max;
break;
}
}
}
필요한 파일 복사
[root@localhost nginx-0.8.37]# cp /usr/local/nginx/mime.types /usr/local/nginx/conf/
서비스 시작
[root@localhost nginx-0.8.37]# /etc/rc.d/init.d/nginx start
nginx (을)를 시작 중: [ OK
[root@localhost nginx-0.8.37]# ps -ef | grep nginx
root 17334 1 0 13:44 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 17335 17334 0 13:44 ? 00:00:00 nginx: worker process
nobody 17337 17334 0 13:44 ? 00:00:00 nginx: worker process
웹페이에서 확인