Nginx ("engine x") 是一個高性能的 HTTP 和 反向代理 服務器,也是一個 IMAP/POP3/SMTP 代理服務器。 Nginx 是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 站點開發(fā)的,第一個公開版本0.1.0發(fā)布于2004年10月4日。其將源代碼以類BSD許可證的形式發(fā)布,因它的穩(wěn)定性、豐富的功能集、示例配置文件和低系統(tǒng)資源的消耗而聞名。
安裝Nginx依賴庫
安裝gcc g++的依賴庫
ubuntu平臺可以使用如下命令。
apt-get install build-essentialapt-get install libtool
centeros平臺可以使用如下命令。
centos平臺編譯環(huán)境使用如下指令
安裝make:
yum -y install gcc automake autoconf libtool make
安裝g++:
yum install gcc gcc-c++
安裝 pcre依賴庫(http://www.pcre.org/)
sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev
安裝 zlib依賴庫(http://www.zlib.net)
apt-get install zlib1g-dev
安裝 ssl依賴庫
apt-get install openssl
安裝Nginx(http://nginx.org)
#下載最新版本:wget http://nginx.org/download/nginx-1.11.3.tar.gz#解壓:tar -zxvf nginx-1.11.3.tar.gz#進入解壓目錄:cd nginx-1.11.3#配置:./configure --prefix=/usr/local/nginx #編輯nginx:make注意:這里可能會報錯,提示“pcre.h No such file or directory”,具體詳見:http://stackoverflow.com/questions/22555561/error-building-fatal-error-pcre-h-no-such-file-or-directory 需要安裝 libpcre3-dev,命令為:sudo apt-get install libpcre3-dev#安裝nginx:sudo make install#啟動nginx:sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 注意:-c 指定配置文件的路徑,不加的話,nginx會自動加載默認路徑的配置文件,可以通過 -h查看幫助命令。#查看nginx進程:ps -ef|grep nginx
Nginx常用命令
啟動 Nginx
/usr/local/nginx/sbin/nginx./sbin/nginx
停止 Nginx
./sbin/nginx -s stop./sbin/nginx -s quit
-s都是采用向 Nginx 發(fā)送信號的方式。
Nginx重新加載配置
./sbin/nginx -s reload
指定配置文件
./sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-c表示configuration,指定配置文件
查看 Nginx 版本
有兩種可以查看 Nginx 的版本信息的參數。第一種如下:
./sbin/nginx -v nginx: nginx version: nginx/1.0.0
另一種顯示的是詳細的版本信息:
poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -Vnginx: nginx version: nginx/1.0.0nginx: built by gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4)nginx: TLS SNI support enablednginx: configure arguments: --with-http_ssl_module --with-openssl=/home/luming/openssl-1.0.0d/
檢查配置文件是否正確
poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -tnginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok2012/01/09 16:45:09 [emerg] 23898#0: open() "/usr/local/nginx/logs/nginx.pid" failed (13: Permission denied)nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
如果出現如上的提示信息,表示沒有訪問錯誤日志文件和進程,可以sudo(super user do)一下:
poerchant@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
如果顯示如上,則表示配置文件正確。否則,會有相關提示。
顯示幫助信息
poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -h
或者:
poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -?
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答