linux下 nginx安裝

1.什么是Nginx

Nginx是一款高性能的http 服務(wù)器/反向代理服務(wù)器及電子郵件(IMAP/POP3)代理服務(wù)器。

個(gè)人理解:
1)服務(wù)器端的一個(gè)軟件
2)把服務(wù)器接受ip請求的功能分離出來,相當(dāng)于攔截請求,單獨(dú)的處理客戶端請求,分發(fā)給具體的服務(wù)器,以便負(fù)載均衡,給服務(wù)器減壓.

先安裝環(huán)境

1、需要安裝gcc的環(huán)境。
yum install gcc-c++
2、第三方的開發(fā)包。
? PCRE
PCRE(Perl Compatible Regular Expressions)是一個(gè)Perl庫,包括 perl 兼容的正則表達(dá)式庫。nginx的http模塊使用pcre來解析正則表達(dá)式,所以需要在linux上安裝pcre庫。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre開發(fā)的一個(gè)二次開發(fā)庫。nginx也需要此庫。
? zlib
zlib庫提供了很多種壓縮和解壓縮的方式,nginx使用zlib對http包的內(nèi)容進(jìn)行g(shù)zip,所以需要在linux上安裝zlib庫。
yum install -y zlib zlib-devel

? openssl
OpenSSL 是一個(gè)強(qiáng)大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協(xié)議,并提供豐富的應(yīng)用程序供測試或其它目的使用。
nginx不僅支持http協(xié)議,還支持https(即在ssl協(xié)議上傳輸http),所以需要在linux安裝openssl庫。
yum install -y openssl openssl-devel

開始安裝

第一步:把nginx的源碼包上傳到linux系統(tǒng)
第二步:解壓縮
[root@localhost ~]# tar zxf nginx-1.8.0.tar.gz
第三步:使用configure命令創(chuàng)建一makeFile文件。
./configure
--prefix=/usr/local/nginx
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--with-http_gzip_static_module
--http-client-body-temp-path=/var/temp/nginx/client
--http-proxy-temp-path=/var/temp/nginx/proxy
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi
--http-scgi-temp-path=/var/temp/nginx/scgi
注意:啟動nginx之前,上邊將臨時(shí)文件目錄指定為/var/temp/nginx,需要在/var下創(chuàng)建temp及nginx目錄
[root@localhost sbin]# mkdir /var/temp/nginx/client -p
第四步:make
第五步:make install

image.png

進(jìn)入sbin目錄
[root@localhost sbin]# ./nginx //我做的時(shí)候用這個(gè)啟動nginx,下邊的報(bào)錯,一些路徑或者文件不存在,路徑不存在,我可以造,但是文件不存在,我就不會弄了,因?yàn)椴恢纼?nèi)容是啥!比較坑

關(guān)閉nginx:
[root@localhost sbin]# ./nginx -s stop
推薦使用:
[root@localhost sbin]# ./nginx -s quit

重啟nginx:
1、先關(guān)閉后啟動。
2、刷新配置文件:
[root@localhost sbin]# ./nginx -s reload

檢查nginx配置文件內(nèi)容是否正確:./nginx -t
出現(xiàn)以下提示,說明文件內(nèi)容沒問題:
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

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

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

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