当前位置: 首页 > news >正文

nginx-下载功能-状态统计-访问控制

nginx-下载功能-状态统计-访问控制

  • 一、利用nginx做网站提供下载功能
    • 1. 进入nginx存放配置文件目录
    • 2. 编辑nginx.conf文件,开启下载功能
    • 3. 检查nginx.conf主配置文件是否正确
    • 4. 重启nginx服务
    • 5. 修改首页文件index.html
    • 6. 访问首页
    • 7. 去网页根目录下新建download目录
    • 8. 访问download页面
  • 二、状态统计
    • 1. 添加路由配置
    • 2. 重启nginx服务
    • 3. 访问nginx
  • 三、访问控制
    • 1. 基于ip地址
    • 2. 基于用户认证


一、利用nginx做网站提供下载功能

1. 进入nginx存放配置文件目录

[root@web-2 logs]# cd /usr/local/nginx1/conf/
[root@web-2 conf]# ls
fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf
fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default


2. 编辑nginx.conf文件,开启下载功能

[root@web-2 conf]# vim nginx.confserver {listen       80;server_name  www.feng.com;access_log  logs/feng.com.access.log  main;error_log  logs/feng.com.error.log;location / {root   html/feng.com;index  index.html index.htm;autoindex on;  #添加配置可以提供下载功能的指令}

3. 检查nginx.conf主配置文件是否正确

[root@web-2 conf]# nginx -t
nginx: the configuration file /usr/local/nginx1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1/conf/nginx.conf test is successful

4. 重启nginx服务

[root@web-2 conf]# nginx -s reload


5. 修改首页文件index.html

[root@web-2 conf]# cd /usr/local/nginx1/html/feng.com/
[root@web-2 feng.com]# vim index.html 
<html><head><title>sanchuang</title></head><body><p><h1>welcome to sanchuang</h1></p><p><a href="http://www.feng.com/download">http://www.feng.com/download</a></p></body>
</html>

修改网页,不需要去刷新nginx服务,只要刷新浏览器


6. 访问首页

  1. 在浏览器里去访问http://www.feng.com首页文件

浏览器中访问

  1. linux中访问 -> curl
[root@web-2 feng.com]# curl  http://www.feng.com
<html><head><title>sanchuang</title></head><body><p><h1>welcome to sanchuang</h1></p><p><a href="http://www.feng.com/download">http://www.feng.com/download</a></p></body>
</html>

7. 去网页根目录下新建download目录

[root@web-2 feng.com]# cd /usr/local/nginx1/html/feng.com/
[root@web-2 feng.com]# mkdir download
[root@web-2 feng.com]# ls
404.html download index.html

在download目录下新建文件,提供下载测试使用

建议download目录下不要出现index.html,如果有的话,会自动显示index.html页面的内容

[root@web-2 feng.com]# cd download/
[root@web-2 download]# cp /boot . -r
[root@web-2 download]# touch feng.txt
[root@web-2 download]# touch zhang.txt
[root@web-2 download]# cp /etc/hosts .
[root@web-2 download]# ls
boot feng.txt hosts index.html.back index.html.back2 passwd zhang.txt


8. 访问download页面

点击即可下载
在这里插入图片描述


二、状态统计

状态统计功能,默认是没有开启的,需要在编译安装的时候,指定参数开启
--with-http_stub_status_module

1. 添加路由配置

[root@web-2 nginx1]# cd /usr/local/nginx1/conf/
[root@nginx-1 conf]# vim nginx.confserver {listen       80;server_name  localhost;location / {root   html;index  index.html index.htm;}#添加下面的路由配置location = /status {stub_status;}

2. 重启nginx服务

[root@nginx-1 conf]# nginx -t
nginx: the configuration file /usr/local/nginx1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1/conf/nginx.conf test is successful
[root@nginx-1 conf]# nginx -s reload


3. 访问nginx

可以使用ip地址或者域名,接上/status
http://192.168.100.157/status

得到如下状态信息

Active connections: 2 
server accepts handled requests9 9 15 
Reading: 0 Writing: 1 Waiting: 1 
  • Active connections
    当前活动的客户端连接数,包括Waiting连接数。
  • accepts
    接受的客户端连接总数。
  • handled
    已处理的连接总数。通常,参数值与accepts 除非达到某些资源限制(例如, worker_connections限制)相同。
  • requests
    客户端请求总数。
  • Reading
    nginx正在读取请求标头的当前连接数。 --》读取请求报文
  • Writing
    nginx正在将响应写回到客户端的当前连接数。 --》返回响应报文
  • Waiting
    当前等待请求的空闲客户端连接数 --》占着茅坑不拉屎的人的数量

三、访问控制

1. 基于ip地址

allow和deny指令将按其定义的顺序应用

deny

[root@nginx-1 conf]# vim nginx.conflocation = /status {stub_status;deny 192.168.100.1;}[root@nginx-1 conf]# nginx -t
nginx: the configuration file /usr/local/nginx1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1/conf/nginx.conf test is successful
[root@nginx-1 conf]# nginx  -s reload

allow

[root@nginx-1 conf]# vim nginx.conflocation = /status {stub_status;allow 192.168.100.1;deny all;}[root@nginx-1 conf]# nginx  -t
nginx: the configuration file /usr/local/nginx1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1/conf/nginx.conf test is successful
[root@nginx-1 conf]# nginx  -s reload

2. 基于用户认证

编辑配置文件,重启nginx服务

[root@nginx-1 conf]# vim nginx.conflocation = /status {stub_status;auth_basic "status auth";  #添加的配置auth_basic_user_file  htpasswd;  #添加的配置allow 192.168.100.1;deny all;}
[root@nginx-1 conf]# nginx  -t
nginx: the configuration file /usr/local/nginx1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1/conf/nginx.conf test is successful
[root@nginx-1 conf]# nginx  -s reload

新建htpasswd文件

[root@nginx-1 conf]# yum install httpd-tools -y
[root@nginx-1 conf]# htpasswd -c /usr/local/nginx1/conf/htpasswd cali
New password: 
Re-type new password: 
Adding password for user cali
# 查看生成的用户名和密码文件内容
[root@nginx-1 conf]# cat htpasswd  
cali:$apr1$6yRM3Suq$wf5MfqAMtRKFE9oxIPSsz/

访问验证是否生效,支持用户名和密码认证
使用浏览器去访问

在这里插入图片描述

http://www.xdnf.cn/news/1335529.html

相关文章:

  • Qt 中最经典、最常用的多线程通信场景
  • 安装electron报错的解决方法
  • 【Express零基础入门】 | 构建简易后端服务的核心知识
  • jvm三色标记
  • imx6ull-驱动开发篇30——Linux 非阻塞IO实验
  • 机器学习--数据清洗—(续篇)
  • 算法 ----- 链式
  • 基础笔记8.20
  • 【运维进阶】shell三剑客
  • RK-Android11-PackageInstaller安装器自动安装功能实现
  • 福昕PDF编辑软件高级版下载与详细图文安装教程!!
  • 力扣 30 天 JavaScript 挑战 第36天 第8题笔记 深入了解reduce,this
  • 【嵌入式电机控制#34】FOC:意法电控驱动层源码解析——HALL传感器中断(不在两大中断内,但重要)
  • day075-MySQL数据库服务安装部署与基础服务管理命令
  • 《算法导论》第 35 章-近似算法
  • imx6ull-驱动开发篇31——Linux异步通知
  • 极其简单二叉树遍历JAVA版本
  • 虚拟机部署HDFS集群
  • Redisson最新版本(3.50.0左右)启动时提示Netty的某些类找不到
  • VR交通安全学习机-VR交通普法体验馆方案
  • 从防抖节流到链表树:编程世界中的抽象优化艺术
  • C++智能指针详解:告别内存泄漏,拥抱安全高效
  • Flask高效数据库操作指南
  • C++ MFC/BCG编程:文件对话框(CFileDialog、CFolderPickerDialog)
  • CFBench评测
  • (一)关于步进电机的FOC控制
  • DeepSeek大模型如何重塑AI Agent?从技术突破到行业落地
  • 意象框架:连接感知与认知的统一信息结构分析——基于上古汉语同源词意义系统的词源学与认知语言学探索
  • (认识异常)
  • SED项目复现学习实录