您当前的位置: 首页 >  centos

小志的博客

暂无认证

  • 1浏览

    0关注

    1217博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Nginx—— random_index模块详解(Centos7通过yum方式安装)

小志的博客 发布时间:2021-07-05 23:04:39 ,浏览量:1

目录
    • 一、random_index的编译参数作用
    • 二、http_random_index_module的配置
    • 三、random_index的配置演示
    • 四、random_index配置演示的注意事项

一、random_index的编译参数作用 编译选项作用–with-http_random_index_module目录中选择一个随机主页 二、http_random_index_module的配置
  • Syntax:random_index on|off 表示语法是stub_status on 或者stub_status off
  • Default:random_index off 表示默认关闭
  • Context:location 表示需要location块中进行配置
三、random_index的配置演示

1、先创建是三个html页面,上传到/opt/app/html目录下,以便配置好random_index编译参数后随机访问/opt/app/html目录下的所有html页面。

  • indexone.html页面

    
    
    	
    	titleone
    
    
    	
    
    
  • indextwo.html页面

    
    
    	
    	titletwo
    
    
    	
    
    
  • indexthree.html页面

    
    
    	
    	titlethree
    
    
    	
    
    

在这里插入图片描述 2、编辑nginx.conf配置文件

[root@localhost /]# vim /etc/nginx/nginx.conf

在这里插入图片描述 3、在server块的location块中添加如下配置

#配置random_index模块
location /{
     root /opt/app/html;
     random_index on;
}

在这里插入图片描述 4、检查配置修改的配置文件是否正确,返回successful表示配置文件修改无错。否则检查配置文件语法。

[root@localhost /]# nginx -t -c /etc/nginx/nginx.conf

在这里插入图片描述 5、重新加载配置文件

[root@localhost /]# systemctl reload nginx

在这里插入图片描述 6、查看nginx进程

[root@localhost /]# ps -aux |grep nginx

在这里插入图片描述 7、重启nginx服务

[root@localhost /]# systemctl restart nginx.service

8、浏览器输入 localhost 地址,一直刷新该地址,可以看到在/opt/app/html/目录下的三个页面随机切换访问,如下图:

在这里插入图片描述

在这里插入图片描述 在这里插入图片描述

四、random_index配置演示的注意事项
  • 配置random_index编译参数不会随机访问linux目录中的隐藏文件

1、隐藏/opt/app/html/目录下的indexthree .html文件

[root@localhost /]# cd /opt/app/html/
[root@localhost html]# mv indexthree.html .indexthree.html

2、输入 ll -a 命令查看所有文件

[root@localhost html]# ll -a

在这里插入图片描述 3、浏览器再次输入 localhost 地址,一直刷新该地址,可以看到在/opt/app/html/目录下的2个页面随机切换访问,如下图:

在这里插入图片描述在这里插入图片描述

关注
打赏
1661269038
查看更多评论
立即登录/注册

微信扫码登录

0.0399s