1、下載Nginx及相關組件
wget http://nginx.org/download/nginx-1.6.2.tar.gz
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、安裝c++編譯環境,如已安裝可略過
yum install gcc-c++
出現確認,輸入Y
3、安裝Nginx及相關組件
openssl安裝
tar -zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install
zlib安裝
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
pcre安裝
tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure && make && make install
nginx安裝
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install
查看nginx安裝路徑
whereis nginx

查看nginx版本
/usr/local/nginx/sbin/nginx -v
啟動nginx
/usr/local/nginx/sbin/nginx
瀏覽器輸入IP,出現下面界面即為安裝成功

關閉nginx
/usr/local/nginx/sbin/nginx -s stop
nginx命令
啟動: /usr/local/nginx/sbin/nginx
停止: /usr/local/nginx/sbin/nginx -s stop
多載組態檔: /usr/local/nginx/sbin/nginx -s reload
重啟: /usr/local/nginx/sbin/nginx -s reopen
4、配置前端專案
1、把專案放入/**/nginx/html 目錄下
2、config配置
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/ess-web/; #ess-web 為打包的專案檔案夾
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /cors/{ #“cors” 為指向標識
proxy_pass http://192.168.10.22:8080/; #“cors" 所指向的IP路徑
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
5、開機自啟
新建組態檔
/usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/webserver/nginx/sbin/nginx
ExecReload=/usr/local/webserver/nginx/sbin/nginx -s reload
ExecStop=/usr/local/webserver/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable xxx.service 設定某個服務開機啟動systemctl disable xxx.service 設定取消某個服務開機啟動systemctl stop xxx.service 關閉某個服務systemctl status xxx.service 查看某個服務狀態
6、配置Nginx的監控選項:
組態檔路徑:/usr/local/nginx/nginx.conf
添加如下代碼:
#設定Nginx狀態訪問地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
#auth_basic_user_file conf/htpasswd;
}
配置完成重啟Nginx,命令:/usr/local/nginx/nginx -s reload
7、狀態查看
配置完成后在瀏覽器中輸入http://192.168.0.194/NginxStatus查看,顯示資訊如下:

8、 引數說明
active connections – 活躍的連接數量
server accepts handled requests — 總共處理了107520387個連接 , 成功創建107497834次握手, 總共處理了639121056個請求
每個連接有三種狀態waiting、reading、writing
reading —讀取客戶端的Header資訊數.這個操作只是讀取頭部資訊,讀取完后馬上進入writing狀態,因此時間很短,
writing — 回應資料到客戶端的Header資訊數.這個操作不僅讀取頭部,還要等待服務回應,因此時間比較長,
waiting — 開啟keep-alive后等候下一次請求指令的駐留連接.
正常情況下waiting數量是比較多的,并不能說明性能差,反而如果reading+writing數量比較多說明服務并發有問題,
9、補充:
查看Nginx并發行程數:ps -ef | grep nginx | wc -l
查看Web服務器TCP連接狀態:netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/148724.html
標籤:Linux
