前提:在安裝nginx前首先要確認系統中安裝了gcc、pcre-devel、zlib-devel、openssl-devel。
若無:
安裝命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
Nginx下載地址:
http://nginx.org/download/
下載「nginx-1.9.8.tar.gz」,移動到/usr/local/下.
解壓
tar -zxvf nginx-1.9.8.tar.gz
##進入nginx目錄
cd nginx-1.9.8
設定
./configure --prefix=/usr/local/nginx
#make
make
make install
跳轉到剛才設定的安裝目錄/usr/local/nginx/
cd /usr/local/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
cd /usr/local/nginx/sbin
./nginx //啟動nginx
在瀏覽器中輸入(自己的)伺服器的ip地址,如:192.168.1.12
CentOS7的版本linux系統下:
驗證80埠是否開啟命令:
firewall-cmd --query-port=80/tcp
若為no,則開啟80埠,命令如下
( --permanent #永久生效,沒有此引數重新啟動後失效):
firewall-cmd --add-port=80/tcp --permanent
#重新啟動防火牆
systemctl restart firewalld
再次存取瀏覽器:
成功.
5.設定nginx開機啟動
vim /etc/rc.d/rc.local
#開機啟動nginx
/usr/local/nginx/sbin/nginx