1.查看系統環境:
[root@iz8vbg5szfelurur14myszz html]#cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@iz8vbg5szfelurur14myszz html]# uname -r
3.10.0-514.6.2.el7.x86_64
[root@iz8vbg5szfelurur14myszz html]# uname -m
x86_64
2.安裝pcre庫是爲了nginx具備URI重寫功能的rewrite模塊(必用)
yum install pcre pcre-devel -y
rpm -qa pcre pcre-devel
3.nginx使用HTTPS服務會用此模塊,不裝會報錯
yum install openssl openssl-devel -y
rpm -qa openssl openssl-devel
4.創建下載路徑,並從指定的yum源下載
mkdir -p /home/wqb/tools
cd /home/wqb/tools
wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
5.創建nginx的虛擬用戶,並限制登錄
useradd -u 889 -s /sbin/nologin -M nginx
6.解壓安裝包
tar xf nginx-1.6.3.tar.gz
cd nginx-1.6.3
7.進行編譯安裝
configure 參數解釋
--prefix=PATH 指定路徑
--user=USER 進程用戶權限
--group=GROUP 進程用戶組權限
--with-http_stub_status_module 激活狀態信息
--with-http_ssl_module 激活SSL功能
執行相關配置
./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --prefix=/application/nginx-1.6.3
編譯成二進制文件並安裝
make && make install
8.做軟連接是爲了區分版本查看和升級的區分
ln -s /application/nginx-1.6.3/ /application/nginx
9.查看是否安裝成功
[root@iz8vbg5szfelurur14myszz html]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
啓動nginx:
[root@iz8vbg5szfelurur14myszz ~]# /application/nginx/sbin/nginx
端口查看:
[root@iz8vbg5szfelurur14myszz ~]# netstat -tupln|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18145/nginx: master
[root@iz8vbg5szfelurur14myszz ~]#lsof -i :80
10.瀏覽器驗證
看到這個頁面證明nginx搭建完畢!