日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

CentOS7使用yum安装Nginx

發布時間:2025/3/21 Nginx 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CentOS7使用yum安装Nginx 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

CentOS7使用yum安裝Nginx

文章目錄

  • CentOS7使用yum安裝Nginx
      • 安裝說明
      • 安裝gcc
      • 安裝pcre庫
      • 安裝zlib庫
      • 安裝OpenSSL庫
      • 安裝Nginx庫
      • 啟動nginx

安裝說明

  • Nginx是一款輕量級的網頁服務器、反向代理服務器。相較于Apache、lighttpd具有占有內存少,穩定性高等優勢。
    它最常的用途是提供反向代理服務。
  • 在Centos下,yum源不提供nginx的安裝,不能直接 yum install nginx進行安裝,但可以通過切換yum源的方法獲取安裝。也可以通過直接下載安裝包的方法
  • 安裝必要的庫(nginx 中gzip模塊需要 zlib 庫,rewrite模塊需要 pcre 庫,ssl 功能需要openssl庫),具體版本號根據實際情況改變。這里其他的庫就默認安裝,我們選定 /usr/local 為nginx的安裝目錄

安裝gcc

查看是否有gcc

gcc -v

如果是新環境,一般沒有gcc,都需要進行安裝

yum install -y gcc gcc-c++

如果中間有提示install need space 20M 之類的信息
對于 Is this ok?[y/d/N] 的選擇,輸入y,即yes的意思。

之后遇到有此類提示都選擇yes

安裝pcre庫

輸入命令:

yum install pcre pcre-devel

如果報錯:configure: error: You need a C++ compiler for C++ support

回到上一步,安裝上gcc就好了

安裝庫的過程中可能會遇到以下錯誤:

Error: Multilib version problems found. This often means that the root
cause is something else and multilib version checking is just
pointing out that there is a problem. Eg.:

  • You have an upgrade for pcre which is missing some dependency that another package requires. Yum is trying to solve this by installing an older version of pcre of the different architecture. If you exclude the bad architecture yum will tell you what the root cause is (which package requires what). You can try redoing the upgrade with --exclude zlib.otherarch … this should give you an error message showing the root cause of the problem.
  • You have multiple architectures of pcre installed, but yum can only see an upgrade for one of those architectures. If you don’t want/need both architectures anymore then you can remove the one with the missing update and everything will work.
  • You have duplicate versions of pcre installed already. You can use “yum check” to get yum show these errors. …you can also use --setopt=protected_multilib=false to remove this checking, however this is almost never the correct thing to do as something else is very likely to go wrong (often causing much more problems).
  • 上述常見原因是有兩個版本的庫。

    用以下命令查看pcre庫:

    rpm -qa | grep pcre

    一般結果會是兩個庫

    pcre-8.32-17.el7.x86_64

    pcre-8.32-17.el7.i686

    用以下命令刪除其中一個版本(這里我們刪除i686)

    yum erase pcre-8.32-17.el7.i686

    當我們再次使用rpm命令查看pcre庫時,就只剩下x86_64庫了

    安裝zlib庫

    輸入命令:

    yum install zlibe zlib-devel

    我們在安裝的過程中可能會碰到和安裝pcre庫一樣的問題,也是采用一樣的解決方法,將命令中的pcre換成zlib就行

    安裝OpenSSL庫

    輸入命令:

    yum install openssl openssl-devel

    安裝Nginx庫

    1. 來到/usr/local 文件夾

    cd /usr/local/

    2. 下載nginx的安裝包

    wget http://nginx.org/download/nginx-1.8.0.tar.gz

    如果系統沒有安裝wget,執行 yum install wget 命令安裝wget,然后再下載nginx的安裝包。

    這里我裝的是nginx的1.8.0版本,大家可以去查nginx的版本然后安裝新版,比如nginx-1.12.0,對應修改即可

    3. 解壓

    tar -zxvf nginx-1.8.0.tar.gz

    4. 來到nginx-1.8.0 文件夾

    cd nginx-1.8.0

    5. 配置

    ./configure

    這是我們采用的是默認配置,在 nginx-1.12.0 版本中你就不需要去配置相關東西,默認就可以了。

    6. 編譯安裝

    make

    make install

    7. 查找安裝路徑

    whereis nginx

    如果不知道nginx裝在哪里了,使用whereis命令進行查找

    8. 啟動、停止nginx

    進入nginx的啟動目錄

    cd /usr/local/nginx/sbin/

    下面是四種對nginx的操作:

  • 啟動nginx
  • ./nginx

  • 關閉nginx。stop是先查出nginx進程id再使用kill命令強制殺掉進程。
  • ./nginx -s stop

  • 關閉nginx。quit是待nginx進程處理任務完畢再進行停止。
  • ./nginx -s quit

  • 重新加載nginx
  • ./nginx -s reload

    重啟時推薦先使用quit/stop關閉,再啟動nginx

    如果是修改了nginx.conf中的配置信息,想讓配置生效。不必關閉nginx,用reload重新加載即可


    啟動nginx

    進入nginx的啟動目錄下啟動nginx

    最后一步,在瀏覽器中輸入自己的ip地址(默認80端口),如果看到 Welcome to Nginx 界面,即配置成功。

    《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的CentOS7使用yum安装Nginx的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。