Install Nginx On Amazon EC2
This guide can be used in the case we need to run Nginx on Amazon due to a bug that affects the EPEL package repository and maybe some other repository.
That’s why I leave this “Step by Step” to compile and build the RPM for CentOS and RHEL. It is functional in Amazon EC2 instances.
The first thing you need to do is to install the “checkinstall” to generate the RPM.If you’re going to do it on a 32bit system just do the following:
yum install checkinstall
To do that we have to have the RPMforge Repository in our system.
If we have a 64 bits system we are going to need to download the checkinstall 32bits RPM using the following link, and install it:
wget http://packages.sw.be/checkinstall/checkinstall-1.6.0-3.el5.rf.i386.rpm
rpm -Uvh checkinstall-1.6.0-3.el5.rf.i386.rpm
Then install the needed RPM packages to compile Nginx:
yum install rpm-devel rpm-build openssl-devel zlib-devel pcre pcre-devel gcc make
Now we have to download the Nginx code and generate the RPM:
mkdir -p /root/src
cd /root/src
wget http://nginx.org/download/nginx-0.8.54.tar.gz
tar xzf nginx-0.8.54.tar.gz
cd nginx-0.8.54
We are now ready to compile and generate the RPM:
./configure --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin/ --prefix=/usr/share/nginx --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid
make
checkinstall --fstrans=no
We need to follow the steps asked by checkinstall and then install the generated RPM.Finally we have to copy and paste in a file to add to “init.d” and then be able to run it as any service.By the end of this “Step by Step” there is an example of how to do it.As a last step we only have to start it like a normal service.
vim /etc/init.d/nginx # Paste here the example named "Example to start service"
/etc/init.d/nginx start
I hope this to be usefull for you. If we want to use, for example, PHP 5.2 we can download PHP and Nginx compatible with Amazon Kernel(Xen Kernel) from the CentosALT Repository.
Example to start service.
#!/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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
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
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest_q || configtest || return 6
stop
start
}
reload() {
configtest_q || configtest || return 6
echo -n $"Reloading $prog: "
killproc $nginx -HUP
echo
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
configtest_q() {
configtest >/dev/null 2>&1
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
# Upgrade the binary with no downtime.
upgrade() {
local pidfile="/var/run/${prog}.pid"
local oldbin_pidfile="${pidfile}.oldbin"
configtest_q || configtest || return 6
echo -n $"Staring new master $prog: "
killproc $nginx -USR2
retval=$?
echo
sleep 1
if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then
echo -n $"Graceful shutdown of old $prog: "
killproc -p ${oldbin_pidfile} -QUIT
retval=$?
echo
return 0
else
echo $"Something bad happened, manual intervention required, maybe restart?"
return 1
fi
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
force-reload|upgrade)
rh_status_q || exit 7
upgrade
;;
reload)
rh_status_q || exit 7
$1
;;
status|status_q)
rh_$1
;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;
*)
echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart}"
exit 2
esac
Source: Netman Blog
Tags: amazon apache centos checkinstall config ec2 EPEL nginx rhel rpmforge Server
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.