linux版本:CentOS7 64位
【yum 安裝最新版nginx:https://www.cnblogs.com/xxoome/p/7256214.html】
在安裝nginx前首先要確認系統中安裝了gcc、pcre-devel、zlib-devel、openssl-devel。
Linux下檢查是否安裝過某軟件包:http://www.cnblogs.com/xxoome/p/5866553.html
安裝命令:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
nginx下載地址:https://nginx.org/download/
下載“nginx-1.9.9.tar.gz”,移動到/usr/local/下。
## 解壓 tar -zxvf nginx-1.9.9.tar.gz ##進入nginx目錄 cd nginx-1.9.9
## 配置
./configure --prefix=/usr/local/nginx
# make
make
make install
OK,現在可以執行make 了。
執行make、make install命令
測試是否安裝成功
# 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
啟動nginx
cd /usr/local/nginx/sbin ./nginx //啟動nginx
在瀏覽器中輸入服務器的ip地址,如:192.168.1.12
很不幸,打不開鏈接。下面進行原因排查:
說明服務器的80端口是打不開的。
因為我使用的linux系統版本是CentOS7,所以可以在服務器中執行如下命令來驗證》》
firewall-cmd --query-port=80/tcp
顯然80端口沒有開啟。
下面我們開啟80端口:
firewall-cmd --add-port=80/tcp --permanent
#重啟防火牆
systemctl restart firewalld
--permanent #永久生效,沒有此參數重啟后失效
刷新瀏覽器
====================== 分割線 ====================
配置完畢!
2、配置nginx開機自啟動
vim /etc/rc.d/rc.local
配置環境:
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
解釋:
ln –s 源文件 目標文件夾
源文件: /usr/local/nginx/sbin/nginx 就是nginx位置
目標文件夾: /usr/local/bin/ 就是環境變量目錄
執行完上述操作后, nginx就可以全局訪問了