解决redis不能访问本机的真实ip地址问题

1.我在进行用jedis来连接redis时出现了问题:

我用Jedis jedis = new Jedis("127.0.0.1",6379);可以成功连接,但是我如果把127.0.0.1换成的本机地址如192.168.1.103发现会报错.

2.解决这个问题要修改redis.windows.conf的配置文件(说明一下我的redis是在windows版的)

这里要改两个地方:
1.修改bind的ip
2.修改protected-mode yes为protected-mode no
我的修改如下

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 192.168.1.103

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

上面的代码可以看到我的修改了哪些东西,之后再尝试连接一下

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容