一、安裝之前的准備
1、配置yum源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下載新的阿里雲yum源
yum makecache #重新建立軟件緩存
2、安裝基本依賴與開發環境:
[root@localhost src]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
3、安裝PCRE:
[root@localhost src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@localhost src]# tar zxvf pcre-8.35.tar.gz
[root@localhost src]# cd pcre-8.35/
[root@localhost src-8.35]# ./configure
[root@localhost pcre-8.35]# make && make install
4、查看PCRE版本號:
[root@localhost pcre-8.35]# pcre-config --version
8.35
[root@localhost pcre-8.35]# cd ..
二、安裝nginx
1、下載nginx軟件包
[root@localhost src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
[root@localhost src]# tar zxvf nginx-1.6.2.tar.gz #解壓
2、編譯安裝nginx
cd nginx-1.6.2
[root@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/src/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make && make install
3、進入nginx中的sbin目錄
[root@localhost nginx-1.6.2]# cd /usr/local/src/nginx/sbin/
[root@localhost sbin]# ls
nginx
4、查看nginx版本號
[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.6.2
[root@localhost sbin]#
三、nginx配置
1、創建用戶
[root@localhost sbin]# groupadd lishiqi #創建組
[root@localhost sbin]# useradd -g lishiqi lishiqi #創建用戶並指定組,也可以不指定組,不指定組的時候就不用進行創建組的操作了!
2、nginx.conf配置文件備份
[root@localhost sbin]# cd ../conf/
[root@localhost conf]# ls
[root@localhost conf]# cp nginx.conf nginx.conf.back #復制文件
[root@localhost conf]# vim nginx.conf
頂部添加了user lishiqi lishiqi;
5、啟動nginx
[root@localhost conf]# /usr/local/src/nginx/sbin/nginx
6、檢查nginx啟動情況
[root@zwxlsq conf]# ps -ef | grep nginx
7、瀏覽器訪問nignx:
[root@localhost conf]# firewall-cmd --add-port=80/tcp --permanent #開啟80端口
success
[root@localhost conf]# firewall-cmd --reload #重新加載防火牆
success
[root@localhost conf]#
直接在瀏覽器中輸入IP地址就可以進行訪問
五、基本命令:
/usr/local/src/nginx/sbin/nginx -s reload #重新載入配置文件
/usr/local/src/nginx/sbin/nginx -s reopen #重啟服務
/usr/local/src/nginx/sbin/nginx -s stop #停止服務