0


Nginx网站服务

一、Nginx

一款高性能、轻量级Web服务软件
1.稳定性高
2.系统资源消耗低.
3.对HTTP并发连接的处理能力高
单台物理服务器可支持30000 ~ 50000个并发请求

二、监控

1.准备环境

yum -y install gcc gcc-c++ pcre-devel zlib-devel make

2.创建用户

useradd -M -s /sbin/nologin nginx

3. 解压并移动

unzip nginx-module-vts-master.zip
mv nginx-module-vts-master /usr/local/
ls /usr/local/

4.编译安装

cd /opt
tar xzvf nginx-1.15.9/
cd nginx-1.15.9/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--add-module=/usr/local/nginx-module-vts-master/    

add  module     添加模块 

make && make install

5.路径优化

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

6.确认

nginx -t   检查配置文件是否配置正确

7.修改配置文件

cd /usr/lib/systemd/system
vim nginx.service

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile =/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.targe

chmod 754 /lib/systemd/system/nginx.service 
systemctl start nginx.service
systemctl start nginx
systemctl status nginx

cd /usr/local/nginx/conf
vim nginx.conf

vhost_traffic_status_zone;
log_format main '{ "@timestamp": "$time_local", '
'"@fields": { '
'"uri":"$request_uri",'
'"url":"$uri",'
'"upstream_addr":"$upstream_addr",'
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"body_bytes_sent": "$body_bytes_sent", '
'"host":"$host",'
'"server_addr":"$server_addr",'
'"request_time": "$request_time", '
'"request_time":"$request_time",'
'"status":"$status",'
'"request": "$request", '
'"request_method": "$request_method", '
'"size":$body_bytes_sent,'
'"upstream_time":"$upstream_response_time"'
'"http_referrer": "$http_referer", '
'"body_bytes_sent":"$body_bytes_sent", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_user_agent": "$http_user_agent" } }';

location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }

nginx -t   检查配置文件是否配置正确
systemctl status nginx
systemctl restart nginx

netstat -natp | grep nginx     检测存活

8.访问并监控

标签: Nginx

本文转载自: https://blog.csdn.net/Drw_Dcm/article/details/126525429
版权归原作者 Drw_Dcm 所有, 如有侵权,请联系我们删除。

“Nginx网站服务”的评论:

还没有评论