Ubuntu16.04.1 安裝Nginx

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平臺可以使用如下命令。

1

2apt-get install build-essential

apt-get install libtool

centeros平臺可以使用如下命令。

1

2

3

4

5

6centos平臺編譯環(huán)境使用如下指令

安裝make:

yum -y install gcc automake autoconf libtool make

安裝g++:

yum install gcc gcc-c++

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

1

2sudo apt-get update

sudo apt-get install libpcre3 libpcre3-dev

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

1

apt-get install zlib1g-dev

安裝 ssl依賴庫

1

apt-get install openssl

安裝Nginx(http://nginx.org

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19#下載最新版本:

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

1

2

3/usr/local/nginx/sbin/nginx

./sbin/nginx

停止 Nginx

1

2

3./sbin/nginx -s stop

./sbin/nginx -s quit

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

Nginx重新加載配置

1

./sbin/nginx -s reload

指定配置文件

1

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

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

查看 Nginx 版本

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

1

2

3./sbin/nginx -v

nginx: nginx version: nginx/1.0.0

另一種顯示的是詳細的版本信息:

1

2

3

4

5poechant@ubuntu:/usr/local/nginx$ ./sbin/nginx -V

nginx: nginx version: nginx/1.0.0

nginx: builtbygcc 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/

檢查配置文件是否正確

1

2

3

4

5poechant@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 syntaxisok

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)如上的提示信息,表示沒有訪問錯誤日志文件和進程,可以sudo(super user do)一下:

1

2

3poerchant@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntaxisok

nginx: configuration file /usr/local/nginx/conf/nginx.conf testissuccessful

如果顯示如上,則表示配置文件正確。否則,會有相關提示。

顯示幫助信息

1

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

或者:

1

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

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

相關閱讀更多精彩內容

友情鏈接更多精彩內容