ubuntu安裝Nginx

本機:

nginx-1.7.7.tar.gz

pcre-8.34.tar.gz


1、模塊依賴性
gzip 模塊需要 zlib 庫
rewrite 模塊需要 pcre 庫
ssl 功能需要 openssl 庫
預先編譯好的安裝包
sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev


2、nginx的準備工作
下載nginx-1.7.7.tar.gz包到你指定的目錄下後,解壓:
tar zxvf nginx-1.7.7.tar.gz
解壓後在當前目錄下會生成一個nginx-1.7.7的目錄
進入解壓後的目錄,運行configure命令,
 ./configure 
這時會報出一個如下錯誤:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
這是因爲沒有PCRE library的原因所致,通過下面的命令安裝相關的lib即可解決


3、PCRE庫的安裝:
1)解壓:
tar –zxvf pcre-8.34.tar.gz
解壓目錄爲:pcre-8.34
然後進入到 cd pcre-8.34,進行配置、編譯、安裝
2)配置
./configure 
3)編譯pcre
make
make pcre時會出錯
libtool: compile: unrecognized option `-DHAVE_CONFIG_H'
libtool: compile: Try `libtool --help' for more information.
make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/home/mfcai/pcre-8.10'
make: *** [all] Error 2
安裝build-essential
apt-get install build-essential
4)安裝pcre
make install


4、nginx的安裝

./configure 
make
make install

 

Nginx會被安裝在/usr/local/nginx目錄下(也可以使用參數--prefix=指定自己需要的位置),
安裝成功後 /usr/local/nginx 目錄下有四個子目錄分別是:conf、html、logs、sbin 。
其中 Nginx 的配置文件存放於 conf/nginx.conf,
bin文件是位於 sbin 目錄下的 nginx 文件。
確保系統的 80 端口沒被其他程序佔用,運行 sbin/nginx 命令來啓動 Nginx
打開瀏覽器訪問此機器的 IP,如果瀏覽器出現 Welcome to nginx! 則表示 Nginx 已經安裝並運行成功!!!


5、常用命令

#切換到
cd usr/local/nginx/sbin
(權限不夠加sudo!!!)
#啓動
./nginx
#重啓
./nginx -s reload
#判斷配置文件是否正確
./nginx -t
#關閉
./nginx -s stop
或者
查詢nginx主進程號
ps -ef | grep nginx
從容停止   kill -QUIT 主進程號

快速停止   kill -TERM 主進程號

強制停止   kill -9 nginx

若nginx.conf配置了pid文件路徑,如果沒有,則在logs目錄下

kill -信號類型 '/usr/local/nginx/logs/nginx.pid'


參考來自:

blog.sina.com.cn/s/blog_4ad7c2540101duql.html

www.cnblogs.com/jianxie/p/3990377.html


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章