URL重写

url?page = 1 这样的地址,?后面的内容搜索引擎不会收录。可以进行url重写

rewrite语句格式及参数语法

rewrite是实现url重写的重要指令,根据regex的内容重定向到replacemence,结尾是flag标记。

rewrite regex replacemence flag
关键字 正则 替换内容 标记
image.png
image.png

配置

  1. rewrite ^/account/list-([0-9]+).html$ /account/list?pagenum =$1 last;
  1. rewrite ^/account/(.+)/list-([0-9]+).html$ /account/list?pagenum =$2&xx00=$1 last;

实现短网址

长网址是后面很多级目录,如/asdadasda/asdadasda/asdadasda/asdadasda
短网址http://www.short.com/asdadasda
asdadasda这一部分就是key 。
由key解析对应的具体网址可以有两种办法

  1. nginx负载到后面大tomcat应用服务器,连接数据库查到key对应的地址,然后重定向。保存记录后续对访问地址进行分析。
  2. nginx在请求访问是就写日志,连接redis等查询到key对应的地址然后访问。日志内容发送kafka消息队列,等到后续的消费分析。