一、下載原始碼包
復制鏈接打開
鏈接:*https://pan.baidu.com/s/17gUkX-UC9GHTf3rkY8aV_Q*
提取碼:**1314**
~~~~復制這段內容后打開,操作更方便哦~~~~
二、安裝nginx
#下載Nginx原始碼包
[root@web01 ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
#解壓Nginx原始碼包到/opt目錄下,并查看Nginx源檔案結構
[root@web01 ~]# tar -xzvf nginx-1.12.2.tar.gz
#安裝nginx編譯安裝所需要的的依賴
[root@web01 ~]# yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim
Nginx依賴于pcre、zlib、openssl,在編譯前配置時如果有問題
使用yum方式安裝三個包(pcre-devel、zlib-devel、openssl-devel)
#進行編譯前配置
[root@web01 opt]# cd /opt
[root@web01 opt]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
#執行多核編譯安裝
[root@web01 opt]# make - && make install
#啟動nginx,提前先關閉防火墻、seLinux
[root@web01 opt]# setenforce 0
[root@web01 opt]# systemctl stop firewalld
[root@web01 opt]# systemctl disable firewalld
#切換到安裝目錄/usr/local/nginx,查看目錄的結構
[root@web01 opt]# cd /usr/local/nginx
[root@web01 nginx ]# pwd
[root@web01 nginx ]# ls
#然后啟動Nginx
[root@web01 nginx ]# /usr/local/nginx/sbin/nginx
#檢查Nginx行程是否啟動
[root@web01 ~ ]# ps aux | grep nginx
root 3949 0.0 0.1 46436 1152 ? Ss 4月30 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
www 3950 0.0 0.2 46836 2180 ? S 4月30 0:00 nginx: worker process
root 6295 0.0 0.0 112676 976 pts/1 S+ 03:00 0:00 grep --color=auto nginx
3查看Nginx使用的埠號
[root@web01 ~]# netstat -tlnp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3949/nginx: master
#使用本地主機的瀏覽器訪問虛擬機上的Nginx服務器
停止nginx
停止Nginx的三種方式
# 1). 立即停止Nginx服務
[root@web01 ~]# /usr/local/nginx/sbin/nginx -s stop
# 2).完成當前任務后停止
[root@web01 ~]# /usr/local/nginx/sbin/nginx -s quit
# 3).殺死Nginx行程(兩種方式)
[root@web01 ~]# killall nginx
[root@web01 ~]# pkill nginx
#nginx添加環境變數(使用軟連接將nginx鏈接到/usr/local/sbin)
[root@web01 ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin #建立軟連接
[root@web01 ~]# ll /usr/local/sbin/ | grep "nginx"
#顯示當前環境變數PATH
[root@web01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#編輯.bash_profile檔案(添加環境變數)
[root@web01 ~]# vim ~/.bash_profile
..........
export PATH=$PATH:/usr/local/nginx/sbin
......
#多載參考.bash_profile檔案(生效組態檔)
[root@web01 ~]# source ~/.bash_profile
#常用nginx命令(啟動、停止、)
# 啟動nginx
[root@web01 ~]# nginx
# 停止nginx
[root@web01 ~]# nginx -s stop
[root@web01 ~]# nginx -s quit
三、原始碼安裝nginx,自動化安裝腳本實作
#!/bin/bash
# installation configuration
NGINX_VERSION=1.12.2
NGINX_SRC_PATH=/root
NGINX_BIN_PATH=/usr/local/nginx
# disable firewall
systemctl stop firewalld
setenforce 0
# installation dependence
yum install -y pcre-devel zlib-devel openssl-devel wget gcc
# download nginx source package
cd ${NGINX_SRC_PATH}
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
# unzip source package
tar -xzvf nginx-${NGINX_VERSION}.tar.gz
cd ./nginx-${NGINX_VERSION}
# install nginx
./configure --prefix=${NGINX_BIN_PATH} --with-http_ssl_module
make & make install
# start nginx service
cd ${NGINX_BIN_PATH}/sbin
./nginx
# END
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/282908.html
標籤:其他
