NGINX is
better for high-traffic sites due to its event-driven architecture. Rather than
handling each request in a distinct thread, it uses non-blocking I/O to service
many requests in each thread.
In advanced
configurations NGINX runs behind your big web server and handle all requests to
static content and to pass all dynamic requests to primary web-server. With
this solution your big server will spawn additional threads/processes only for
dynamic pages and it will return answers to small frontend very fast and then
can free resources to use them to handle another query.
It is not only useful
to have NGINX serve static images, but having NGINX proxy to Apache is a big win
as well. This is because slow clients cause Apache to keep threads busy for
longer than needed. NGINX can deal with the slow client and allow Apache to
finish the request as fast as possible, freeing the thread (and memory) for
other requests. NGINX will accept the request as fast as your local connection
will allow, and trickle the response back to the slow client.
Many people find that running NGINX as a proxy in front of Apache to be
an ideal middle ground. NGINX talks to the slow clients and can do so using a very small
amount of RAM. When requests are forwarded to Apache, the request speed is
limited by your local connectivity, not that of the remote user. This means
that the network bottleneck will not keep the request (and its memory-hogging
thread) alive for any longer than necessary.
In short you get the low-resource benefits of NGINX
coupled with the wide feature-set of
Apache.
- Download NGINX from following link: http://wiki.nginx.org/Install
- Extract downloaded zip, rename to
‘nginx’ and paste under C drive.
- Open “C:/nginx/” right click on “nginx.exe” file and choose properties. Go to “Compatibility” tab and check “Run this program as administrator” option and click apply button.
- Download NGINX from following link: http://wiki.nginx.org/Install
-
Extract downloaded zip to /home/[user]/
- Navigate to /home/[user]/nginx-1.4.4/ and run the following command in a terminal window. ./configure && make && make install
- However, one disadvantage of installing from source is that init scripts are not created. So, we need to create one for easy control of NGINX and to ensure it restarts on a reboot. If you have placed the NGINX binary in a directory other than ‘/usr/local/nginx/sbin’ then you will need to adjust the script shown below to match your installation.
-
If you have
NGINX running then stop the process using:
kill `cat /usr/local/nginx/logs/nginx.pid’ Create a file with name 'nginx' and copy following script to the file.
!/bin/sh
# nginx - this script starts and stops the nginx daemin
. /etc/rc.d/init.d/functions
. /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-
As
the init file is a shell script, it needs to have executable permissions:
chmod +x /etc/init.d/nginx - Let's
check our work to confirm:
sudo /sbin/chkconfig --list nginx nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off The script will now be called on a reboot so Nginx will automatically start.
.
Running NGINX On Windows 07.
You will probably get a popup to allow the service in Windows Firewall, accept it. Then head to
Running NGINX On RHEL 5.x.
Running NGINX On Windows 07.
- start nginx #start server
- nginx -s stop #fast shutdown
- nginx -s quit #graceful shutdown
- nginx -s reload #reload the configuration file
- nginx -s reopen #re-opening log file
You will probably get a popup to allow the service in Windows Firewall, accept it. Then head to
http://127.0.0.0:80
and you should see a welcome page for nginxRunning NGINX On RHEL 5.x.
-
/etc/init.d/nginx start /etc/init.d/nginx stop/etc/init.d/nginx restart/etc/init.d/nginx reloa/etc/init.d/nginx reloa/etc/init.d/nginx configtes
ORservice nginx starservice nginx stoservice nginx restartservice nginx reloaservice nginx statusservice nginx configtest
Open
error log “
C:/nginx/logs/error.log”.
If you have the following error, this means port 80 is already in use. Possibly
by Apache that is running on your computer.
bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a
socket
in
a way forbidden by its access permissions).
To
resolve this go to “…../nginx/conf/nginx.conf”
and look for: “
listen 80;”. Change the
port number to something like 88.
Save and close. Now try to start NGINX again.
No comments:
Post a Comment