六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 1194|回复: 0

nginx下solr安全 屏蔽外网访问 安全验证

[复制链接]
 楼主| 发表于 2015-11-29 16:19:39 | 显示全部楼层 |阅读模式
nginx下solr安全 屏蔽外网访问 安全验证
一、iptables进行设定指定端口访问:
  1. A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT  #比如你的solr安装商品为8080,如果不是请自行修改为你自己的端口
复制代码
二、nginx进行反向代理并且基础验证:

  1. location /solr/ {
  2.                 proxy_pass   http://127.0.0.1:8983/solr/;
  3.                 proxy_redirect default;
  4.                 auth_basic "Restricted";
  5.                 auth_basic_user_file "/usr/local/nginx/conf/solrAuth.conf";
  6.         }
复制代码
三、下面是生成验证密码文件(/usr/local/nginx/conf/solrAuth.conf):
bash htpasswd.shhtpasswd.sh 中的内容为:
  1. #!/bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH

  4. echo "====================================="
  5. echo "# A tool like htpasswd for Nginx    #"
  6. echo "#-----------------------------------#"
  7. echo "# Author:Licess http://www.lnmp.org #"
  8. echo "====================================="

  9. #set UserName

  10.         username=""
  11.         read -p "Please input UserName:" username
  12.         if [ "$username" = "" ]; then
  13.                 echo "Error:UserName can't be NULL!"
  14.                 exit 1
  15.         fi
  16.         echo "==========================="
  17.         echo "UserName was: $username"
  18.         echo "==========================="

  19. #set password

  20.         unpassword=""
  21.         read -p "Please input the Password:" unpassword
  22.         if [ "$unpassword" = "" ]; then
  23.                 echo "Error:Password can't be NULL!"
  24.                 exit 1
  25.         fi
  26.         echo "==========================="
  27.         echo "Password was: $unpassword"
  28.         echo "==========================="
  29. password=$(perl -e 'print crypt($ARGV[0], "pwdsalt")' $unpassword)

  30. #set htpasswd file

  31.         htfile=""
  32.         read -p "Please input Auth filename:" htfile
  33.         if [ "$htfile" = "" ]; then
  34.                 echo "Error:Auth filename can't be NULL!"
  35.                 exit 1
  36.         fi
  37.         echo "==========================="
  38.         echo "Auth File: /usr/local/nginx/conf/$htfile"
  39.         echo "==========================="

  40.         get_char()
  41.         {
  42.         SAVEDSTTY=`stty -g`
  43.         stty -echo
  44.         stty cbreak
  45.         dd if=/dev/tty bs=1 count=1 2> /dev/null
  46.         stty -raw
  47.         stty echo
  48.         stty $SAVEDSTTY
  49.         }
  50.         echo ""
  51.         echo "Press any key to Creat...or Press Ctrl+c to cancel"
  52.         char=`get_char`

  53. if [ ! -f /usr/local/nginx/conf/$htfile.conf ]; then
  54.   echo "Create Auth file......"
  55. cat >/usr/local/nginx/conf/$htfile.conf<<eof
  56. $username:$password
  57. eof
  58. echo "Create Auth file successful,auth file path:/usr/local/nginx/conf/$htfile.conf."
  59. else
  60.         echo "File already exists,please run this script again."
  61.         exit 1
  62. fi
复制代码
nginx下solr安全 屏蔽外网访问 安全验证

该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表