从零开始的Linux运维屌丝之路,资源免费分享平台   运维人员首选:简单、易用、高效、安全、稳定、社区活跃的开源软件
  • 首页
  • Nginx
  • Nginx功能模块 密码认证 状态信息 日志在线浏览

Nginx功能模块 密码认证 状态信息 日志在线浏览

发布:蔺要红05-15分类: Nginx

 

Nginx http 功能模块

Nginx http 功能模块

             模块说明

  ngx_http_core_module

  包括一些核心的 http 参数配置,对应 Nginx 的配置为 HTTP 区块部分

  ngx_http_access_module

  访问控制模块,用来控制网站用户对 Nginx 的访问

  ngx_http_gzip_module

  压缩模块,对 Nginx 返回的数据压缩,属于性能优化模块

  ngx_http_fastcgi_module

  FastCGI 模块,和动态应用相关的模块,如 PHP

  ngx_http_proxy_module

  proxy 代理模块

  ngx_http_upstream_module

  负载均衡模块,可实现网站的负载均衡和节点的健康检查

  ngx_http_rewrite_module

  URL 地址重写模块

  ngx_http_limit_conn_module

  限制用户并发连接数以及请求数的模块

  ngx_http_limit_req_module

  根据定义的 key 限制 Nginx 请求过程的速率

  ngx_http_log_module

  访问日志模块,以指定的格式记录 Nginx 客户访问日志等信息

  ngx_http_auth_basic_module

  Web 认证模块,设置 Web 用户通过账号密码访问 Nginx

  ngx_http_ssl_module

  ssl 模块,用于加密的 http 连接,如 https

  ngx_http_stub_status_module

  记录 Nginx 基本访问状态信息等的模块



Nginx server 密码认证
location  ^~  /yaohong/ {
    auth_basic "Authorized users only";
    auth_basic_user_file /www/server/nginx/conf/htpasswd; 
    }

# 设置账号密码文件方法一:
printf "111111:$(openssl passwd -crypt 111111)\n" >>htpasswd  #设置用户名111111 密码111111
# 设置账号密码文件方法二:
yum -y install httpd-tools
htpasswd -c /application/nginx-1.14.2/conf/htpasswd  linyaohong

加上认证之后该目录下的php文件将不会被解析,会运行下载,如果要使其能够解析php可以,可将上面的配置改为:

location  ^~  /yaohong/ {
    try_files $uri =404;
    fastcgi_pass  unix:/tmp/php-cgi-54.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    include pathinfo.conf;
    auth_basic "Authorized users only";  #提示信息,可以自行修改
    auth_basic_user_file /www/server/nginx/conf/htpasswd;  #认证文件
    } 

# ^~ 代表优先匹配、如果不设置优先匹配会去匹配外面解析php文件的location、那么就不会走认证
# 所以这里设置优先匹配,而优先匹配以后需要解析php文件、所以需要再设置解析php的配置


Nginx server 状态信息查看

location /nginx_status {
    stub_status on;
    access_log off;
    #allow 127.0.0.1; 
    #deny all;
}



Nginx server 日志在线浏览
location /logs {
    alias /server/logs;  #定义到其他目录
    autoindex  on;       #开启在线浏览,显示目录
    autoindex_exact_size off; #off  显示出文件的大小
    autoindex_localtime on;   #按照服务器时间显示
    add_header Cache-Control no-store;  #不进行缓存,每次访问的时间必须从服务器上读取最新的数据
    allow 10.10.10.200;
    deny all;
	}

# 另外需要在mime.types里添加
[root@web01 conf]# cat mime.types
types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/log                                         log;
 
温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,如有侵权我会在24小时之内删除!

欢迎使用手机扫描访问本站