Nginx (engine x) 是一個高效能的HTTP和反向代理伺服器,也是一個IMAP/POP3/SMTP伺服器,具有佔用記憶體少,併發能力強的優點,被廣泛應用。本文主要介紹在Linux環境下用原始碼安裝Nginx伺服器的步驟。
Nginx與Apache、Lighttpd,是當前主流的三大Web伺服器。
演示環境:CentOS 6。5 + nginx-1。14。0
1. 安裝前準備環境
1。1 安裝編譯Nginx所需的相關軟體包
[root@ecs-6cf5src]# yum -y install gcc-c++ pcre* openssl*
2. 下載解壓原始碼包
2。1 原始碼包下載
在Nginx官網http://nginx。org找到nginx-1。14。0,點選nginx-1。14。0。tar。gz,瀏覽器會自動開始下載,右鍵選擇複製連結地址,獲取該檔案的URL,然後在CentOS主機上用wget命令下載原始碼包
[root@ecs-6cf5 ~]# cd /usr/local/src/
[root@ecs-6cf5 src]# wget http://nginx。org/download/nginx-1。14。0。tar。gz
2。2 解壓到/usr/local/目錄下
[root@ecs-6cf5 src]# tar -xvf nginx-1。14。0。tar。gz -C /usr/local/
3. 安裝Nginx
3。1 配置原始碼
[root@ecs-6cf5 src]# 。/configure ——prefix=/usr/local/nginx
如果在配置過程中沒有報錯,則繼續以下步驟編譯並安裝Nginx。
3。2 編譯並安裝Nginx
[root@ecs-6cf5 src] make && make install
4. 啟動Nginx服務
[root@ecs-6cf5 src]# cd /usr/local/nginx/sbin
[root@ecs-6cf5 src]# 。/nginx
檢視程序,可以看到nginx的master和worker程序
[root@ecs-33b2 sbin]# ps -ef | grepnginx
root 24508 1 0 16:04 ? 00:00:00 nginx: master process 。/nginx
nobody 24509 24508 0 16:04 ? 00:00:00 nginx:worker process
root 24511 20643 0 16:04 pts/1 00:00:00 grepnginx
可以透過訪問ip:80測試,看到頁面這樣的提示就說明安裝成功
至此,Nginx伺服器安裝並執行成功。
重啟Nginx的命令:
[root@ecs-33b2 sbin]# 。/nginx -s reload
停止Nginx:查程序號之後kill -9 程序號 即可
以上就是CentOS上透過原始碼方式安裝Nginx的方法了,若有疑問,歡迎新增測試交流群交流。
測試交流QQ群:736371980
諮詢電話/微信:19983568393
關注公眾號,瞭解更多測試技術