引言:Elasticsearch的IK分词器可以配置远程词典,以实现热更新,远程词典的创建可以用Nginx实现, 本文主要介绍nginx实现url访问静态文件的配置方式。
/path/words/custom_words.txt
夏天
可乐
快乐水
cd /etc/nginx/conf.d 进入nginx配置路径
touch remote_words_url.conf 创建nginx配置文件
# remote_words_url.conf
server
{
listen 9001; # 监听端口
server_name 192.xxx.xxx.xxx; # 服务器IP
location /dic/custom_words.txt { # 文件相对路径(访问时会用到)
alias /path/words/custom_words.txt; # 文件本地所在路径
}
}
注:
①alias会把指定路径当作文件路径,而root会把指定路径拼接到文件路径后,再进行访问。
②Nginx是非root用户启动的,会因为权限问题遇到访问不到文件的情况,这时可将目录的权限调整为755
③Nginx能实现通过不同的url前缀访问不同的前后端项目
注:如果需要配置整个文件夹下的所有文件,比如 /path/words
下所有文件
# remote_words_url.conf
server
{
listen 9001;
server_name 192.xxx.xxx.xxx;
charset 'utf-8';
location /dic/ {
alias /path/words/;
}
}
注意:
autoindex off
防止列出目录内容nginx -t # 检测配置文件是否正确
systemctl restart nginx
curl http://192.xxx.xxx.xxx:9001/dic/custom_words.txt