11 linux安裝nginx含ubuntu

0 參考
https://www.cnblogs.com/piscesLoveCc/p/5794926.html

1 安裝Nginx依賴庫

1.1安裝gcc g++的依賴庫
ubuntu平臺(tái)可以使用如下命令。

    apt-get install build-essential
    apt-get install libtool

centeros平臺(tái)可以使用如下命令。
centos平臺(tái)編譯環(huán)境使用如下指令
安裝make:

    yum -y install gcc automake autoconf libtool make`

安裝g++:

    yum install gcc gcc-c++  

1.2 安裝 pcre依賴庫(http://www.pcre.org/

       sudo apt-get update
       sudo apt-get install libpcre3 libpcre3-dev

1.3安裝 zlib依賴庫(http://www.zlib.net

    apt-get install zlib1g-dev

1.4 安裝 ssl依賴庫

    apt-get install openssl

2 安裝Nginx(http://nginx.org

#下載最新版本:
wget http://nginx.org/download/nginx-1.11.3.tar.gz
#解壓:
tar -zxvf nginx-1.11.3.tar.gz
#進(jìn)入解壓目錄:
cd nginx-1.11.3
#配置:
./configure --prefix=/usr/local/nginx 
#編輯nginx:
make
注意:這里可能會(huì)報(bào)錯(cuò),提示“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
#啟動(dòng)nginx:
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路徑,不加的話,nginx會(huì)自動(dòng)加載默認(rèn)路徑的配置文件,可以通過 -h查看幫助命令。
#查看nginx進(jìn)程:
ps -ef|grep nginx

3 Nginx常用命令

3.1啟動(dòng) Nginx

/usr/local/nginx/sbin/nginx
 
./sbin/nginx 

3.2停止 Nginx

./sbin/nginx -s stop
 
./sbin/nginx -s quit

-s都是采用向 Nginx 發(fā)送信號(hào)的方式。

3.3Nginx重新加載配置

./sbin/nginx -s reload

3.4指定配置文件

./sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-c表示configuration,指定配置文件

3.5查看 Nginx 版本
有兩種可以查看 Nginx 的版本信息的參數(shù)。第一種如下:

./sbin/nginx -v
 
nginx: nginx version: nginx/1.0.0

另一種顯示的是詳細(xì)的版本信息:

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -V
nginx: nginx version: nginx/1.0.0
nginx: built by gcc 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
nginx: TLS SNI support enabled
nginx: configure arguments: --with-http_ssl_module --with-openssl=/home/luming/openssl-1.0.0d/

3.6檢查配置文件是否正確

poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -t
nginx: [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 ok
2012/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

如果出現(xiàn)如上的提示信息,表示沒有訪問錯(cuò)誤日志文件和進(jìn)程,可以sudo(super user do)一下:

poerchant@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -t
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

如果顯示如上,則表示配置文件正確。否則,會(huì)有相關(guān)提示。

3.7顯示幫助信息

poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -h

或者:

poechant@ubuntu:/user/local/nginx$ ./sbin/nginx -?

c'd

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容