1. 程式人生 > 實用技巧 >安裝nginx--伺服器:CentOS 7.6

安裝nginx--伺服器:CentOS 7.6

在安裝nginx前首先要確認系統中安裝了gcc、pcre-devel、zlib-devel、openssl-devel。
安裝命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

官網nginx下載地址:https://nginx.org/download/
下載“nginx-1.16.1.tar.gz”,移動到/usr/local/下。
wget -c https://nginx.org/download/nginx-1.16.1.tar.gz

解壓安裝
tar -zxvf nginx-1.16.1.tar.gz

進入nginx目錄
cd nginx-1.16.1.tar.gz

//配置
./configure --prefix=/usr/local/nginx

//make

make
make install

測試是否安裝成功
cd到剛才配置的安裝目錄/usr/loca/nginx/
./sbin/nginx -t

這個時候會報錯
錯誤資訊:
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
2016/09/13 19:08:56 [emerg] 6996#0: open() "/usr/local/nginx/logs/access.log" failed (2: No such file or directory)
原因分析:nginx/目錄下沒有logs資料夾

解決方法:

mkdir logs
chmod 700 logs

正常情況的資訊輸出:

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

cd /usr/local/nginx/sbin
./nginx //啟動nginx

在命令列視窗測試一下80埠是否通
ping 埠號:80

連線失敗
我使用的linux系統版本是CentOS7,所以可以在伺服器中執行如下命令來驗證》》
firewall-cmd --query-port=80/tcp


顯然80埠沒有開啟。
下面我們開啟80埠:
firewall-cmd --add-port=80/tcp --permanent

重啟防火牆
systemctl restart firewalld

** --permanent #永久生效,沒有此引數重啟後失效**
開啟瀏覽器輸入ip回車

成功