Nginx只能處理80端口和25端口的負載均衡,既Nginx只能做郵件和web服務的負載均衡1、下載穩(wěn)定版本的nginx. http://nginx.org/en/download.html
2、按照如下命令安裝
#檢查系統(tǒng)路徑[root@localhost usr]# pwd/usr#解壓到當前路徑[root@localhost usr]# tar -zxv -f nginx-1.6.2.tar.gz #刪除壓縮包[root@localhost usr]# rm -rf nginx-1.6.2.tar.gz #進入到解壓包下[root@localhost usr]# cd nginx-1.6.2/[root@localhost nginx-1.6.2]# 查看安裝時的功能模塊信息[root@localhost nginx-1.6.2]# ./configure --help#指定安裝路徑[root@localhost nginx-1.6.2]# ./configure --PRefix=/usr/local/nginx#編譯[root@localhost nginx-1.6.2]# make#安裝[root@localhost nginx-1.6.2]# make install#回退到解壓縮包上級目錄[root@localhost usr]# cd ../#解除解壓縮包[root@localhost usr]# rm nginx-1.6.2 -rf
上面安裝使用默認參數(shù)進行配置,如果要自定義安裝模塊和安裝位置可以進行如下參數(shù)配置:
[root@localhost nginx-1.6.2]# ./configure /> --prefix=/usr/local/nginx /> --sbin-path=/usr/local/nginx/sbin/nginx /> --conf-path=/usr/local/nginx/conf/nginx.conf /> --http-log-path=/usr/local/nginx/logs/access.log /> --error-log-path=/usr/local/nginx/logs/error.log /> --pid-path=/usr/local/nginx/logs/nginx.pid /> --lock-path=/usr/local/nginx/lock/nginx.lock /> --http-client-body-temp-path=/usr/local/nginx/client_body_temp /> --http-proxy-temp-path=/usr/local/nginx/proxy_temp /> --http-fastcgi-temp-path=/usr/local/nginx/fastcgi-temp /> --http-uwsgi-temp-path=/usr/local/nginx/uwsgi-temp /> --http-scgi-temp-path=/usr/local/nginx/scgi-temp /> --user=root /> --group=root /> --with-http_ssl_module /> --with-http_flv_module /> --with-http_mp4_module /> --with-http_gzip_static_module /> --with-http_stub_status_module
3、安裝缺少包提示
錯誤提示 ./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=<path> option.解決方案[root@localhost nginx-1.6.2]# yum -y install pcre-devel
錯誤提示 ./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib=<path> option.解決方案[root@localhost nginx-1.6.2]# yum install -y zlib-devel
錯誤提示:./configure: error: the HTTP cache module requires md5 functionsfrom OpenSSL library. You can either disable the module by using--without-http-cache option, or install the OpenSSL library into the system,or build the OpenSSL library statically from the source with nginx by using--with-http_ssl_module --with-openssl=<path> options.解決方案[root@localhost nginx-1.6.2]# yum -y install openssl openssl-devel
上面出現(xiàn)的問題是因為沒有安裝Nginx相應的編譯工具,所以在安裝時可以先執(zhí)行如下命令進行安裝
[root@localhost ~]# yum -y install gcc gcc-c++ autoconf automake[root@localhost ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
#說明:
#zlib:Nginx提供gzip模塊,需要zlib庫支持#openssl:Nginx提供ssl功能#pcre:支持抵制重寫rewrite功能
4、修改防火墻配置:
#修改防火墻配置:[root@localhost nginx]# vi + /etc/sysconfig/iptables#添加配置項-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT#重啟防火墻
[root@localhost nginx]# service iptables restart
5、啟動nginx
#方法1
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #方法2
[root@localhost nginx]# cd /usr/local/nginx/sbin [root@admin sbin]# ./nginx
6、監(jiān)察Nginx配置文件語法
[root@localhost sbin]# ./nginx -t -c /usr/local/nginx/conf/nginx.confnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
7、查看nginx是否啟動
[root@localhost nginx]# netstat -ntlp

或者
#測試端口[root@localhost nginx]# netstat –na|grep 80
#瀏覽器中測試http://ip:80
附錄:
#查詢nginx主進程號[root@localhost sbin]# ps -ef | grep nginx#停止進程[root@localhost sbin]# kill -QUIT 主進程號#快速停止[root@localhost sbin]# kill -TERM 主進程號#強制停止[root@localhost sbin]# pkill -9 nginx
Nginx服務腳本

[root@localhost init.d]# service nginx Usage: /etc/init.d/nginx {start|stop|reload|restart|configtest}[root@localhost init.d]# cat nginx #!/bin/bash## chkconfig: - 85 15# description: nginx is a World Wide Web server. It is used to serve# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"RETVAL=0prog="Nginx"start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL}stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL}reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL}restart(){ stop start}configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0}case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1esacexit $RETVALView Code 轉(zhuǎn)載請注明出處:[http://m.survivalescaperooms.com/zhoulf/archive/2013/02/09/2909653.html]
新聞熱點
疑難解答