標籤:nginx
1. Nginx安裝1.1預先準備
CentOS系統下,安裝Nginx的庫包依賴。安裝命令如下:
sudo yum groupinstall "DevelopmentTools"sudo yum install pcre pcre-develsudo yum install zlib zlib-develyum install perl-ExtUtils-Embedsudo yum install openssl openssl-devel
1.2 安裝
最重要的特性和基於http和https內容的模組化,configuration參數可以這樣:
./configure --prefix=/usr/local/nginx-1.5.13--user=app --group=app --with-http_ssl_module --with-http_realip_module
安裝所有必要的模組:
./configure --user=app --group=app--with-http_ssl_module --with-http_realip_module --with-http_addition_module--with-http_xslt_module --with-http_image_filter_module--with-http_geoip_module --withhttp_sub_module --with-http_dav_module--with-http_flv_module --withhttp_mp4_module --with-http_gzip_static_module--with-http_random_index_module --with-http_secure_link_module--with-http_stub_status_module --with-http_perl_module--with-http_degradation_module
使用root使用者,或者管理使用者來執行這個命令。
sudo make & sudo make install
….cp conf/scgi_params '/usr/local/nginx-1.5.13/conf/scgi_params.default'test -f '/usr/local/nginx-1.5.13/conf/nginx.conf' || cp conf/nginx.conf'/usr/local/nginx-1.5.13/conf/nginx.conf'cp conf/nginx.conf '/usr/local/nginx-1.5.13/conf/nginx.conf.default'test -d '/usr/local/nginx-1.5.13/logs' || mkdir -p'/usr/local/nginx-1.5.13/logs'test -d '/usr/local/nginx-1.5.13/logs' || mkdir -p'/usr/local/nginx-1.5.13/logs'test -d '/usr/local/nginx-1.5.13/html' || cp -R html'/usr/local/nginx-1.5.13'test -d '/usr/local/nginx-1.5.13/logs' || mkdir -p'/usr/local/nginx-1.5.13/logs'make[1]: Leaving directory `/home/app/Downloads/nginx-1.5.13'
1.3 測試
測試Nginx配置是否正確,可以使用下列命令:
啟動Nginx
#sudo /usr/local/nginx-1.5.13/sbin/nginx
瀏覽頁面http://localhost,得到的結果:
Welcome to nginx!
2 使用命令
安裝成功Nginx後,有必要瞭解一下基本的命令。
nginx –s stop Stops the daemon immediately (using the TERM signal)nginx –s quit Stops the daemon gracefully (using the QUIT signal)nginx –s reopen Reopens the log filesnginx –s reload Reloads the configuration
停掉nginx進程,輸入命令:
killall nginx
測試組態是否成功:
[[email protected] sbin]$ sudo/usr/local/nginx/sbin/nginx -t[sudo] password for app:nginx: the configuration file/usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file/usr/local/nginx/conf/nginx.conf test is successful
瞭解有關Nginx命令,輸入:
[[email protected]]$ ./nginx -hnginxversion: nginx/1.5.13Usage:nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -q : suppress non-error messages during configuration testing -ssignal : send signal to a masterprocess: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out ofconfiguration file
下面一個表中呈現了不同運行層級和它們的含義。
對系統的進程的運行層級有一定瞭解後,我們將Nginx加到系統服務(service)中。需要在/etc/init.d目錄下,建立nginx指令碼。例如,nginx指令碼可以這樣配置:
---------------------------------------------------------------------------------------------------
保持後,修改執行許可權。
#sudo chmod +x /etc/init.d/nginx
重新啟動Nginx:
sudo /usr/init.d/nginx reload
添加nginx到自動啟動檔案清單中:
sudo chkconfig –add nginx
檢測nginx的運行層級:
[[email protected]~]$ sudo chkconfig --list nginxnginx 0:off 1:off 2:off 3:off 4:off 5:off 6:off