Nginx-模块应用
利用nginx服务搭建网站文件共享服务器
1、编写配置文件
nginx模块功能:ngx_http_autoindex_module
location / {
    autoindex on;
}
Syntax:    autoindex on | off;
Default:    
autoindex off;
Context:    http, server, location
server {
    listen          80;
    server_name     www.test.top;
    location        / {
            root    /html/www;
            index   test.html;
            autoindex on;        #开启nginx站点目录索引功能
     }
PS:
1.需要将首页文件删除
2.mime.types媒体资源类型文件作用
文件中又得扩展名信息资源,进行访问时会直接看到数据信息
文件中没有到扩展名信息资源,进行访问时会直接下载资源
网站页面目录数据,中文出现乱码,如何解决:
location / {
        root    /html/www;
        index   test.html;
        autoindex on;
        charset utf-8;        #修改目录结构中出现的中文乱码
}
利用nginx服务搭建配置文件别名功能
1、编写配置文件
server_name        www.test.com old.com;
2、配置好DNS解析信息
利用nginx状态模块功能对网站进行监控
状态模块: ngx_http_stub_status_module
location = /basic_status {
    stub_status;
}    
1、编写配置文件
server {
        listen        80;
        server_name   state.test.top;
        stub_status;
}
2、重启nginx服务,并且编写解析文件
systemctl reload nginx
10.0.0.7    status.test.com
Active connections:  激活的连接数信息  4000用户  3500
accepts: 接收的连接数汇总(综合)  TCP
handled: 处理的连接数汇总(综合)  TCP
requests: 总计的请求数量  HTTP协议请求 
Reading: nginx服务读取请求报文的数量    100人点餐
Writing: nginx服务响应报文信息数量      100人响应
Waiting: nginx队列机制,要处理(读取或者响应保存进行保存)   监控
nginx服务location作用说明
模块说明: ngx_http_core_module
location进行匹配(uri)
错误页面优雅显示
location /test {
   root /html/www;
   error_page  404  /01.jpg;
}
location /oldgirl {
   root /html/www;
   error_page  404  /02.jpg;
}
location详细配置:
Syntax:    location [ = | ~ | ~* | ^~ ] uri { … }
           location @name { … }
Default:    —
Context:    server, location
location = / {              # 精确匹配    优先级01 最高
    [ configuration A ]
}
    
location / {                # 默认匹配    优先级04 最低
        [ configuration B ]
}
    
location /documents/ {      # 按照目录进行匹配    优先级03
        [ configuration C ]
}
    
location ^~ /images/ {      # 优先匹配/不识别uri信息中符号信息  优先级02
        [ configuration D ]
}
     
location ~* \.(gif|jpg|jpeg)$ {  # 不区分大小写进行匹配  优先级03
        [ configuration E ]
}
利用nginx实现页面跳转功能
利用rewrite模块是跳转功能: http_rewrite_module
Syntax:  rewrite regex replacement [flag];   rewite  匹配的正则信息  替换成什么信息
Default:    —
Context:    server, location, if
    
rewrite www.test.com/(.*) http://www.test.com/$1 permanent;   重写规则配置
     ^/(.*)
baidu.com    /  test.html                  跳转方式
    
www.baidu.com/test.html
跳转方式:
永久跳转:  permanent   301    会将跳转信息进项缓存
临时跳转:  redirect    302    不会缓存跳转信息
出现无限跳转如何解决:
第一种方法: 利用不同server区块配置打破循环
server {
  server_name  test.com;
  rewrite ^/(.*) http://www.test.com/$1 permanent;
}
第二种方法: 利用if判断实现打破循环
if ($host ~* “^test.com$”) {
   rewrite ^/(.*) http://www.test.com/$1 permanent;
}

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号