Nginx网站服务

目录

一、Nginx

二、监控

1.准备环境

2.创建用户 

3. 解压并移动

 4.编译安装

 5.路径优化

 6.确认

7.修改配置文件

 8.访问并监控

三、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.tar.gz
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网站服务配置

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

location / {
    root   html;
    index  index.html index.htm;
    deny   192.168.22.128;  禁止访问
    allow  all;
}


systemctl restart nginx

location / {
    root   html;
    index  index.html index.htm;
    allow  all;
    deny   192.168.22.128;  允许访问
}

vim /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4: :1
localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.22.128 wwow . ls.com www . accp.com

 

mkdir -p /var/www/html/ls /var/www/html/accp
cd /var/www/html/
ls
echo "<h1>hellow</h1>" > ls/index.html
echo "<h1>hellow</h1>" > accp/index.html
ls *

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

server {
   listen             80;
   server_name        www.accp.com;
   charset utf-8;
   access_log         logs/accp.access.log  main;
   location / {
       root   /var/www/html/accp;
       index  index.html index.htm;
}
location /status {
    vhost_traffic_status_display;
    vhost_traffic_status_display _format html;
}
error page    500  502  503 504   /50x.html;
location = /50x.html {
    root   html;
}



server {
   listen             80;
   server_name        www.ls.com;
   charset utf-8;
   access_log         logs/ls.access.log  main;
   location / {
       root   /var/www/html/ls;
       index  index.html index.htm;
}
location /status {
    vhost_traffic_status_display;
    vhost_traffic_status_display _format html;
}
error page    500  502  503 504   /50x.html;
location = /50x.html {
    root   html;
}

nginx -t
systemctl restart nginx
curl www.ls.com
curl www.accp.com

  

cd /var/www/html/
mv ls benet8080
mv accp benet80
cd benet80
vim index.html 

cd benet8080
vim index.html 

 

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


server {
   listen             192.168.22.128:80;
   server_name        www.benet.com;
   charset utf-8;
   access_log         logs/benet80.access.log  main;
   location / {
       root   /var/www/html/benet80;
       index  index.html index.htm;
}
location /status {
    vhost_traffic_status_display;
    vhost_traffic_status_display _format html;
}
error page    500  502  503 504   /50x.html;
location = /50x.html {
    root   html;
}



server {
   listen             192.168.22.128:8080;
   server_name        www.benet.com;
   charset utf-8;
   access_log         logs/benet8080.access.log  main;
   location / {
       root   /var/www/html/benet8080;
       index  index.html index.htm;
}
location /status {
    vhost_traffic_status_display;
    vhost_traffic_status_display _format html;
}
error page    500  502  503 504   /50x.html;
location = /50x.html {
    root   html;
}


systemctl restart nginx

 

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

http {
include       mime.types;
default_type  application/octet-stream;
vhost_traffic_status zone;
server_tokens off;            关闭版本号

systemctl restart nginx

curl -I 192.168.22.128

vim /opt/nginx-1.15.9/src/core/nginx.h
cd /opt/nginx-1.15.9/src/core/
vim nginx.h

cd /opt/nginx-1.15.9/
./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module 
或者
> --add-module=/usr/local/nginx-module-vts-master/

 

vim nginx.conf

http {
include       mime.types;
default_type  application/octet-stream;
vhost_traffic_status zone;
server_tokens on;            开启版本号


systemctl restart nginx
curl -I 192.168.22.128

vim nginx.conf

location ~ \.(gif|jpg|jepg|png|bmp|ico)$ {
    root html;
    expires 1d;
}

nginx -t

cd ..
cd html/
vim index.html 

<img srce"a .ipg"/>    添加内容

  

  • 46
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 42
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 42
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值