zoukankan      html  css  js  c++  java
  • nginx访问认证【访问nginx需要用户名密码】

    ###

    访问认证主要用于企业内部人员访问的地址上,例如:企业网站后台,MySQL客户端phpmyadmin、企业内部的CRM、WIKI网站平台等。

    > 创建密码认证文件并进行授权

    1)创建密码文件
    yum install httpd-tools -y
    htpasswd -bc /wx/nginx/conf/htpasswd admin 123456
    2)授权(有些nginx安装权限设置400会出现权限错误,详情查看nginx错误日志)
    chmod 744 /application/nginx/conf/htpasswd     
      

    > 修改nginx配置 - 重启nginx

    注意:如果需要对不同location做不同的认证,server下面不可以写root html/www;,需要将路径全部写到对应的location中,否则会有500报错


    [root@web02 extra]# vim www.conf server { listen
    80;
    # root html/www; server_name www.etiantian.org; location
    / { root html/www; index index.html index.htm; auth_basic "登录认证"; auth_basic_user_file /wx/nginx/conf/htpasswd; } location /download {
    # 下载文件所在目录 alias
    /etc/nginx/html/download; auth_basic "登录认证"; auth_basic_user_file /wx/nginx/conf/htpasswd1; } } ############################################################ ##参数说明: auth_basic 语法:auth_basic straining|off; 默认值:auth_basic off; 使用位置:http、server、location、limit_except auth_basic_user_file 语法:auth_basic_user_file 默认值:—— 使用位置:http、server、location、limit_except auth_basic_user_file参数后接认证密码文件

    > 测试配置结果

    [root@web02 www]# curl -u admin www.etiantian.org
    Enter host password for user 'admin':
    web01 www.etiantian.org

    ###

     

  • 相关阅读:
    bite one's tongue
    你以为你以为的教育是教育吗?[转]
    使用ngnix通过uwsgi app容器部署django项目
    使用ngnix通过uwsgi app容器部署django项目
    vue作为前端的静态代码与后端融合
    linux下的下载器软件
    git的gui client终端
    java 查找bug的工具 SpotBugs 和 Findbugs
    awesome c, awesome c++
    加密货币即时交换平台 Changelly vs ShapeShift vs CoinSwitch vs ChangeNOW
  • 原文地址:https://www.cnblogs.com/faithH/p/14517868.html
Copyright © 2011-2022 走看看