深刻理解Nginx之Nginx完整安裝
阿新 • • 發佈:2017-05-26
特性 一個 kconfig tool nginx腳本 roo filter com directive
1. Nginx安裝
1.1預先準備
CentOS系統下,安裝Nginx的庫包依賴。
安裝命令例如以下:
sudo yum groupinstall "DevelopmentTools" sudo yum install pcre pcre-devel sudo yum install zlib zlib-devel yum install perl-ExtUtils-Embed sudo 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 files nginx –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 ok nginx: configuration file/usr/local/nginx/conf/nginx.conf test is successful
了解有關Nginx命令,輸入:
[[email protected]]$ ./nginx -h nginxversion: nginx/1.5.13 Usage: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 nginx nginx 0:off 1:off 2:off 3:off 4:off 5:off 6:off
深刻理解Nginx之Nginx完整安裝