CentOS7安裝Nginx并配置自動(dòng)啟動(dòng)的方法步驟
1、官網(wǎng)下載安裝包
http://nginx.org/en/download.html,選擇適合Linux的版本,這里選擇最新的版本,下載到本地后上傳到服務(wù)器或者centos下直接wget命令下載。

切換到/usr/local目錄,下載軟件包
# cd /usr/local # wget http://nginx.org/download/nginx-1.11.5.tar.gz
2、安裝nginx
先執(zhí)行以下命令,安裝nginx依賴庫,如果缺少依賴庫,可能會(huì)安裝失敗,具體可以參考文章后面的錯(cuò)誤提示信息。
# yum install gcc-c++ # yum install pcre # yum install pcre-devel # yum install zlib # yum install zlib-devel # yum install openssl # yum install openssl-devel
解壓安裝包
# tar -zxvf nginx-1.11.5.tar.gz
nginx被解壓到了/usr/local/nginx-1.11.5 目錄下(不要把壓縮包解壓到/usr/local/nginx目錄下,或者將解壓后的目錄重命名為nginx,因?yàn)閚ginx會(huì)默認(rèn)安裝到/usr/local/nginx目錄下),切換到nginx-1.11.5/目錄
# cd /usr/local/nginx-1.11.5/
執(zhí)行# ./configure
# ./configure
該操作會(huì)檢測當(dāng)前系統(tǒng)環(huán)境,以確保能成功安裝nginx,執(zhí)行該操作后可能會(huì)出現(xiàn)以下幾種提示:
checking for OS
+ Linux 3.10.0-123.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
如果出現(xiàn)以上錯(cuò)誤提示信息,執(zhí)行yum install gcc-c++安裝gcc,
./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=<path> option.
如果出現(xiàn)上面提示,表示缺少PCRE庫
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
如果出現(xiàn)以上提示,表示缺少zlib庫
如果沒有出現(xiàn)./configure: error提示,表示當(dāng)前環(huán)境可以安裝nginx,執(zhí)行make和make install編譯nginx
# make # make install
沒有出錯(cuò)的話,表示nginx已經(jīng)成功安裝完成,默認(rèn)安裝位置為/usr/local/nginx,之前的/usr/local/nginx-1.11.5/可以刪除掉了。
如果出現(xiàn)cp: 'conf/koi-win' and '/usr/local/nginx/conf/koi-win' are the same file,可能是你把安裝包解壓到了/usr/local/nginx目錄,解決辦法是將該目錄重命名為其他名稱后再執(zhí)行make,make install.
3、配置nginx開機(jī)啟動(dòng)
切換到/lib/systemd/system/目錄,創(chuàng)建nginx.service文件vim nginx.service
# cd /lib/systemd/system/ # vim nginx.service
文件內(nèi)容如下:
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx reload ExecStop=/usr/local/nginx/sbin/nginx quit PrivateTmp=true [Install] WantedBy=multi-user.target
退出并保存文件,執(zhí)行systemctl enable nginx.service使nginx開機(jī)啟動(dòng)
# systemctl enable nginx.service
systemctl start nginx.service 啟動(dòng)nginx
systemctl stop nginx.service 結(jié)束nginx
systemctl restart nginx.service 重啟nginx
4、驗(yàn)證是否安裝成功
輸入http://服務(wù)器IP/ 如果能看到nginx的界面,就表示安裝成功了

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Nginx+Tomcat負(fù)載均衡集群安裝配置案例詳解
Nginx是一款非常優(yōu)秀的http服務(wù)器軟件,它能夠支持高達(dá)50000個(gè)并發(fā)連接數(shù)的相應(yīng),Nginx+Tomcat負(fù)載均衡集案列是應(yīng)用于生產(chǎn)環(huán)境的一套可靠的Web站點(diǎn)解決方案,對(duì)Nginx Tomcat負(fù)載均衡集群相關(guān)知識(shí)感興趣的朋友一起看看吧2021-10-10
Nginx+PHP(FastCGI)搭建高并發(fā)WEB服務(wù)器(自動(dòng)安裝腳本)第二版
Nginx 0.7.x + PHP 5.2.10(FastCGI)搭建勝過Apache十倍的Web服務(wù)器(第5版) 編寫2011-04-04
使用Nginx部署前端Vue項(xiàng)目的實(shí)現(xiàn)
本文主要介紹了使用Nginx部署前端Vue項(xiàng)目的實(shí)現(xiàn),通過將這兩者結(jié)合起來,我們可以高效地托管我們的前端應(yīng)用,下面就一起來介紹一下,感興趣的可以了解一下2024-09-09
Nginx請(qǐng)求訪問控制實(shí)現(xiàn)方案
Nginx并不直接實(shí)現(xiàn)漏桶算法或令牌桶算法,但這些算法在控制網(wǎng)絡(luò)流量和請(qǐng)求速率方面非常有用,這些算法通常在網(wǎng)絡(luò)編程、API服務(wù)、負(fù)載均衡等領(lǐng)域中使用,以確保系統(tǒng)的穩(wěn)定性和性能,這篇文章給大家介紹Nginx請(qǐng)求訪問控制實(shí)現(xiàn)方案,感興趣的朋友跟隨小編一起看看吧2024-05-05
Nginx 過濾靜態(tài)資源文件的訪問日志的實(shí)現(xiàn)
這篇文章主要介紹了Nginx 過濾靜態(tài)資源文件的訪問日志的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Nginx 如何部署指定文件夾下的項(xiàng)目(本地測試)
這篇文章主要介紹了Nginx 如何部署指定文件夾下的項(xiàng)目(本地測試),分為配置vue.config.js,指定生成環(huán)境的包,配置路由模式為hash(history模式刷新后,找不到頁面),本文講解的非常詳細(xì),需要的朋友可以參考下2024-01-01

