一、安裝所需環境
1、gcc 安裝
yum install gcc-c++
2、PCRE pcre-devel 安裝
yum install -y pcre pcre-devel
3、zlib 安裝
yum install -y zlib zlib-devel
4、OpenSSL 安裝
yum install -y openssl openssl-devel
二、官網下載nginx
1、直接下載.tar.gz安裝包,地址:https://nginx.org/en/download.html
2、使用wget命令下載(推薦)
wget -c https://nginx.org/download/nginx-1.14.0.tar.gz
三、解壓
tar -zxvf nginx-1.14.0.tar.gz
四、配置makefile
為了防止 重啟nginx后 報如下異常:
[root@localhost sbin]# nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory 。
推薦使用默認配置
進入到nginx-1.14.0目錄下
cd nginx-1.14.0
1、使用默認配置(個人 強烈推薦)
./configure
2、自定義配置(不推薦)
此方法可以網上搜索查看,這里我就不列出來了。
五、編譯安裝
1、make
2、make install
六、防火牆開啟80端口
1、開啟防火牆
systemctl start firewalld.service
2、防火牆開啟80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
3、重啟防火牆
firewall-cmd --reload 或者 service firewalld restart
4、查看端口列表
firewall-cmd --permanent --list-port
七、查找安裝路徑
whereis nginx
八、啟動nginx
cd到nginx安裝目錄的bin目錄下啟動nginx
cd /usr/local/nginx/sbin/
./nginx
九、查詢nginx進程
ps aux|grep nginx
十、 驗證是否安裝啟動成功 (前提:先啟動nginx)
打開瀏覽器,輸入安裝nginx服務器的CentOS系統的IP地址,看到如下的頁面時,說明安裝啟動成功了。
十一、 停止nginx
./nginx -s stop
./nginx -s quit
附加說明:
./nginx -s quit:此方式停止步驟是待nginx進程處理任務完畢進行停止。
./nginx -s stop:此方式相當於先查出nginx進程id再使用kill命令強制殺掉進程。
十二、設置ngnix開機自啟
1、編輯 rc.local 文件
cd /etc/rc.d/
vim /etc/rc.d/rc.local
添加如下參數(此參數就是你的nginx啟動程序所在的路徑,這里根據個人安裝的nginx位置而定,我的nginx是安裝在了/usr/local/下)
增加一行 /usr/local/nginx/sbin/nginx
2、設置執行權限
cd /etc/rc.d/
chmod +x rc.local
3、驗證開機啟動設置是否生效
reboot(重啟系統)
打開瀏覽器,輸入安裝nginx服務器的CentOS系統的IP地址,顯示如下圖的頁面,說明nginx開機自啟設置已生效。
PS:如有問題,請留言,轉載請注明出處 https://www.cnblogs.com/ascd-eg/p/9275441.html