CentOS7安裝Nginx并配置自動啟動實例分析

今天小編給大家分享一下CentOS7安裝Nginx并配置自動啟動實例分析的相關知識點,內(nèi)容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

創(chuàng)新互聯(lián)建站服務項目包括赤壁網(wǎng)站建設、赤壁網(wǎng)站制作、赤壁網(wǎng)頁制作以及赤壁網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,赤壁網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到赤壁省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!

1、官網(wǎng)下載安裝包

選擇適合linux的版本,這里選擇最新的版本,下載到本地后上傳到服務器或者centos下直接wget命令下載。

CentOS7安裝Nginx并配置自動啟動實例分析

切換到/usr/local目錄,下載軟件包

# cd /usr/local
# wget http://nginx.org/download/nginx-1.11.5.tar.gz

2、安裝nginx

先執(zhí)行以下命令,安裝nginx依賴庫,如果缺少依賴庫,可能會安裝失敗,具體可以參考文章后面的錯誤提示信息。

# 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,因為nginx會默認安裝到/usr/local/nginx目錄下),切換到nginx-1.11.5/目錄

# cd /usr/local/nginx-1.11.5/

執(zhí)行# ./configure

# ./configure

該操作會檢測當前系統(tǒng)環(huán)境,以確保能成功安裝nginx,執(zhí)行該操作后可能會出現(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)以上錯誤提示信息,執(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提示,表示當前環(huán)境可以安裝nginx,執(zhí)行make和make install編譯nginx

# make
# make install

沒有出錯的話,表示nginx已經(jīng)成功安裝完成,默認安裝位置為/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開機啟動

切換到/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開機啟動

# systemctl enable nginx.service

systemctl start nginx.service    啟動nginx

systemctl stop nginx.service    結(jié)束nginx

systemctl restart nginx.service    重啟nginx

4、驗證是否安裝成功

輸入http://服務器ip/ 如果能看到nginx的界面,就表示安裝成功了

CentOS7安裝Nginx并配置自動啟動實例分析

以上就是“CentOS7安裝Nginx并配置自動啟動實例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站欄目:CentOS7安裝Nginx并配置自動啟動實例分析
本文網(wǎng)址:http://muchs.cn/article26/gphscg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、Google微信公眾號、靜態(tài)網(wǎng)站域名注冊、面包屑導航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設