我這里安裝的是nginx-1.18.0,在安裝nginx前首先要確認系統中安裝了gcc、pcre-devel、zlib-devel、openssl-devel,如果沒有安裝的話也沒關系,后面會有一些報錯的解決方案,等報錯了再安裝也行,
首先下載nginx-1.18.0,并上傳到/usr/local下,
#解壓
r -zxvf nginx-1.18.0.tar.gz
## 進入nginx目錄下
cd nginx-1.18.0
# 配置
/configure --prefix=/usr/local/nginx
可能遇到的坑:
1.顯示錯誤:[./configure: error: C compiler cc is not found],
是因為沒有執行下列的命令:
yum -y install gcc gcc-c++ autoconf automake make
2.顯示錯誤: ./configure: error: the HTTP rewrite module requires the PCRE library.安裝pcre-devel解決問題:
yum -y install pcre-devel
3.顯示錯誤:error: the HTTP gzip module requires the zlib library.安裝“zlib-devel”即可
yum install -y zlib-devel
如果出現一下界面,則nginx安裝成功:

測驗是否安裝成功:切換到/usr/local/nginx/sbin目錄下,執行:
./nginx -t
出現下面的提示是表示安裝成功,
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
到這一步說明nginx已經安裝成功,執行 ./nginx 就可以啟動了;
接下來在瀏覽器上輸入linux的ip地址,查看能否訪問nginx,如果訪問不了,說明需要開放埠,
yum install firewalld firewall-config
firewall-cmd --add-port=80/tcp --permanent
#重啟防火墻
systemctl restart firewalld
# 如果出現以下例外
Failed to start firewalld.service: Unit is masked
# 執行命令,即可實作取消firewall的鎖定
#解鎖
systemctl unmask firewalld
#啟動
systemctl start firewalld
再次在瀏覽器上訪問,出現一下界面,則說明已經成功了,

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/3563.html
標籤:Linux
