nginx模块

简介: nginx模块


配置nginx官方yum源

http://nginx.org/en/linux_packages.html#RHEL-CentOS

vim /etc/yum.repos.d/nginx.repo

[nginx-stable]

name=nginx stable repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

搭建域名虚拟主机

       安装nginx并通过修改配置文件来指定网站存放目录为/data。

[root@node1 ~]# yum -y install nginx
[root@node1 ~]# mkdir /data
[root@node1 ~]# vim /etc/nginx/conf.d/www.conf
server {
        listen 80;
        server_name www.aaa.com;
        location / {
        root /data;
        index index.html index.htm;
        }
}
[root@node1 ~]# systemctl start nginx
[root@node1 ~]# cd /data/
[root@node1 data]# echo "192.168.1.10" > index.html

       此时可以看到网页存放在/data下,访问浏览器看到内容即可。

nginx索引

       在/data网站下,创建download下载目录,启用索引显示。

[root@node1 ~]# mkdir -p /data/download
[root@node1 ~]# cp -rp /media/nginx-rpm/* /data/download/ //复制网页下载内容到download目录下,文件或安装包都可。
[root@node1 ~]# vim /etc/nginx/conf.d/data.conf //编辑配置文件
server {
        location /download {
        root /data;
        autoindex on; //启用索引显示
        charset utf-8,gbk; //字符编码为中文
        autoindex_exact_size on; //显示文件大小
        autoindex_localtime on; //显示文件创建时间
        }
}
[root@node1 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@node1 ~]# systemctl restart nginx
[root@node1 ~]# chmod -R 707 /data/download/

状态索引

       针对网站启用状态化追踪。(在server字段下添加status模块)

[root@node1 ~]# vim /etc/nginx/conf.d/data.conf
server {
//省略部分内容
        location /status {
        stub_status; //启用状态化追踪
        access_log off; //关闭status的日志记录
        }
}
[root@node1 ~]# systemctl restart nginx

       访问http://192.168.1.10/status,可以看到下图所示内容。

Active connections: 2 当前活跃的连接数

server  accepts 2  当前的总tcp连接数

handled 2 成功的连接数

requests 4 总HTTP请求数

       下面可以通过客户端使用压力测试工具对nginx服务器进行压测。

[root@client ~]# yum -y install httpd-tools

[root@client ~]# ab -c 1000 -n 1000 http://192.168.1.10/status

在次刷新后可以看到相关数据

访问控制

       基于ip限制

       启用access模块,仅允许对内部网段或vpn访问status。在status模块中添加两行内容,测试时可以仅允许一个主机访问或划分子网。

[root@node1 ~]# vim /etc/nginx/conf.d/data.conf
//省略部分内容
location /status {
         stub_status;
         access_log off;
         allow 192.168.1.100; //仅允许1.100主机访问
         deny all; //拒绝所有主机访问
}
[root@node1 ~]# systemctl restart nginx

       测试使用1.100主机访问刷新几次显示正常,再用1.4客户端访问为Forbidden说明配置成功。

 

       基于用户限制

       启用auth模块,设置访问/status用户需要密码验证。

[root@node1 ~]# yum -y install httpd-tools
[root@node1 ~]# htpasswd -b -c /etc/nginx/.auth_conf lisi 123 //用户lisi密码123
Adding password for user lisi
[root@node1 ~]# vim /etc/nginx/conf.d/data.conf
//省略部分内容
location /status {
stub_status;
access_log off;
allow 192.168.1.100;
deny all;
auth_basic "input your passwd:"; //用户登录描述信息
auth_basic_user_file /etc/nginx/.auth_conf; //用户验证文件路径
}
[root@node1 ~]# systemctl restart nginx

       根据下图所示输入用户密码后才能查看status内容,上面因为启用了IP限制,所以只能使用1.100主机访问。


相关文章
|
8天前
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
100 6
|
8天前
|
应用服务中间件 nginx
百度搜索:蓝易云【利用nginx内置ngx_http_mirror_module模块实现流量复制及流量放大】
以上就是使用Nginx内置 `ngx_http_mirror_module`模块实现流量复制和流量放大的简要示例。通过合理配置和利用该模块,可以实现更复杂的流量控制和调试需求。
67 1
|
3天前
|
应用服务中间件 nginx Python
nginx-upload-module模块实现文件断点续传_nginx upload module 断点续传 进度(1)
nginx-upload-module模块实现文件断点续传_nginx upload module 断点续传 进度(1)
|
8天前
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
34 3
|
8天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
42 0
|
8天前
|
消息中间件 关系型数据库 MySQL
使用Nginx的stream模块实现MySQL反向代理与RabbitMQ负载均衡
使用Nginx的stream模块实现MySQL反向代理与RabbitMQ负载均衡
103 0
|
8天前
|
存储 应用服务中间件 nginx
Nginx模块开发:handler模块实现
Nginx模块开发:handler模块实现
33 0
|
8天前
|
存储 应用服务中间件 nginx
Nginx模块开发:模块结构的源码阅读以及过滤器(Filter)模块的实现
Nginx模块开发:模块结构的源码阅读以及过滤器(Filter)模块的实现
75 0
|
8天前
|
存储 应用服务中间件 nginx
Nginx:过滤模块的实现
Nginx:过滤模块的实现
|
8天前
|
存储 负载均衡 网络协议
Nginx: handler 模块的实现
Nginx: handler 模块的实现