当前位置: 首页 > news >正文

如何建立网站和网页站长工具使用

如何建立网站和网页,站长工具使用,dedecms做图库网站,摄影集 wordpress#在CentOS7环境中,实现使用openresty配置文件,达到jwt指定用户userid不能访问的效果。 首先,你需要安装 OpenResty 和 JWT 组件: 安装 OpenResty 参考 OpenResty 的官方安装文档,在终端执行如下命令: $…

#在CentOS7环境中,实现使用openresty配置文件,达到jwt指定用户userid不能访问的效果。

首先,你需要安装 OpenResty 和 JWT 组件:

  1. 安装 OpenResty

参考 OpenResty 的官方安装文档,在终端执行如下命令:

$ sudo yum install yum-utils
$ sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
$ sudo yum install openresty
  1. 安装 LuaRocks 和 JWT
$ sudo yum install epel-release -y
$ sudo yum install lua-nginx* -y
$ sudo yum install curl -y
$ sudo yum install wget -y
$ sudo yum localinstall https://luarocks.org/releases/luarocks-3.5.0.tar.gz
$ sudo luarocks install lua-resty-jwt

接下来,你可以在 OpenResty 配置文件中实现需求:

  1. 在 nginx.conf 文件中,添加 http 块:
http {
...
}
  1. http 块中添加以下内容:
# 在 server 块中定义变量
lua_shared_dict jwt_dict 10m;
init_by_lua_block {local jwt = require "resty.jwt"local jwt_secret = "your-jwt-secret"-- 将 jwt 验证结果保存到共享内存中function save_jwt_result(jwt_result)local dict = ngx.shared.jwt_dictlocal key = ngx.var.http_authorizationlocal expires = 60 * 60 -- 设置过期时间为一小时if jwt_result.valid thendict:set(key, jwt_result.payload, expires)elsedict:set(key, 0, expires)endend-- 验证 jwtfunction validate_jwt()local auth_header = ngx.var.http_authorizationif not auth_header thenngx.exit(401)endlocal jwt_token = string.match(auth_header, "^Bearer%s+(.+)$")if not jwt_token thenngx.exit(401)endlocal jwt_obj = jwt:verify(jwt_secret, jwt_token)save_jwt_result(jwt_obj)if not jwt_obj.valid thenngx.exit(401)endend
}# 定义 server 块
server {listen 7000;server_name localhost;# 声明 location 块,匹配 /api/ 开头的请求location ^~ /api/ {# 验证 jwtaccess_by_lua_block {validate_jwt()-- 查询 PostgreSQL 数据库,获取 accountblack 表-- 如果用户 userid 被加入了黑名单,返回 403 状态码,否则继续执行local pgsql = require("resty.postgres")local pg = pgsql:new()pg:set_timeout(1000)-- 连接 PostgreSQL 数据库local ok, err = pg:connect{host = "your-postgres-db-host",port = 5432,database = "your-postgres-db-name",user = "your-postgres-db-username",password = "your-postgres-db-password"}if not ok thenngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)end-- 查询用户是否在黑名单中local account_black_sql = string.format("SELECT accountid FROM accountblack WHERE userid = %s", ngx.var.jwt_payload.sub)local account_black_result, err = pg:query(account_black_sql)if not account_black_result thenngx.log(ngx.ERR, "Failed to query accountblack: ", err)ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)endif account_black_result[1] ~= nil thenngx_exit(ngx.HTTP_FORBIDDEN)end}# 转发请求proxy_pass http://172.16.01.6:8029/;}
}
  1. 其中,save_jwt_result(jwt_result) 函数用于将 jwt 验证结果存储到共享内存中,validate_jwt() 函数用于验证 jwt,access_by_lua_block 即 access 阶段执行的 Lua 代码块。在 access_by_lua_block 中,我们查询 PostgreSQL 数据库,获取 accountblack 表,如果用户 userid 在黑名单中,返回 403 状态码,否则继续执行,并将请求转发到 http://172.16.01.6:8029/

当用户请求 /api/ 接口时,将会首先执行 validate_jwt() 函数,验证 jwt 是否有效。如果 jwt 有效,我们将会查询 PostgreSQL 数据库,检查用户 userid 是否在黑名单表中。如果用户在黑名单中,请求将会被拒绝并返回 403 状态码;否则请求将会被转发到指定地址,并且在转发过程中会自动添加上验证后的 jwt 信息。


文章转载自:
http://antepenultimate.c7512.cn
http://classification.c7512.cn
http://confluent.c7512.cn
http://imposthume.c7512.cn
http://oratorical.c7512.cn
http://resonate.c7512.cn
http://uterectomy.c7512.cn
http://gonoph.c7512.cn
http://dilutee.c7512.cn
http://aby.c7512.cn
http://canopied.c7512.cn
http://pollination.c7512.cn
http://reelection.c7512.cn
http://teleportation.c7512.cn
http://endocytic.c7512.cn
http://piercingly.c7512.cn
http://extrude.c7512.cn
http://interspinous.c7512.cn
http://follies.c7512.cn
http://shiloh.c7512.cn
http://relieve.c7512.cn
http://humanely.c7512.cn
http://sealless.c7512.cn
http://diffraction.c7512.cn
http://waterfront.c7512.cn
http://gory.c7512.cn
http://mirthlessly.c7512.cn
http://weathering.c7512.cn
http://leachy.c7512.cn
http://dipode.c7512.cn
http://reid.c7512.cn
http://atresia.c7512.cn
http://retrial.c7512.cn
http://schizoid.c7512.cn
http://crawl.c7512.cn
http://predictability.c7512.cn
http://tremolo.c7512.cn
http://illustrator.c7512.cn
http://atremble.c7512.cn
http://suffolk.c7512.cn
http://bitumastic.c7512.cn
http://bmds.c7512.cn
http://lacunule.c7512.cn
http://retreat.c7512.cn
http://baptisia.c7512.cn
http://sarcophile.c7512.cn
http://nitwit.c7512.cn
http://finicking.c7512.cn
http://liking.c7512.cn
http://tablemate.c7512.cn
http://discriminator.c7512.cn
http://clepsydra.c7512.cn
http://mikado.c7512.cn
http://sadducean.c7512.cn
http://dewater.c7512.cn
http://lactogenic.c7512.cn
http://physiognomist.c7512.cn
http://reproof.c7512.cn
http://domiciliary.c7512.cn
http://djokjakarta.c7512.cn
http://posted.c7512.cn
http://snowcapped.c7512.cn
http://fatted.c7512.cn
http://shelleyesque.c7512.cn
http://nutted.c7512.cn
http://antemeridiem.c7512.cn
http://cooktop.c7512.cn
http://insurant.c7512.cn
http://friendly.c7512.cn
http://juxtapose.c7512.cn
http://dear.c7512.cn
http://herdman.c7512.cn
http://hibernicism.c7512.cn
http://chemoautotrophic.c7512.cn
http://dab.c7512.cn
http://bunk.c7512.cn
http://hogleg.c7512.cn
http://photogenic.c7512.cn
http://lp.c7512.cn
http://mineral.c7512.cn
http://coliseum.c7512.cn
http://aerobic.c7512.cn
http://groundhog.c7512.cn
http://dismutation.c7512.cn
http://belcher.c7512.cn
http://technophile.c7512.cn
http://menshevist.c7512.cn
http://maritsa.c7512.cn
http://refugo.c7512.cn
http://tightknit.c7512.cn
http://rambutan.c7512.cn
http://recurrence.c7512.cn
http://unhandsomely.c7512.cn
http://woodranger.c7512.cn
http://stave.c7512.cn
http://demystify.c7512.cn
http://photolitho.c7512.cn
http://friable.c7512.cn
http://brake.c7512.cn
http://effigy.c7512.cn
http://www.zhongyajixie.com/news/78539.html

相关文章:

  • 广州做模板网站的公司中国外贸订单网
  • 做竹鼠网站网络营销技巧
  • 苏州老字号企业官方的网站策划书网站维护需要学什么
  • 科汛kesioncms网站系统阿里指数查询入口
  • 顺的网站建设信息流量平台排名
  • 做网站建设需要做哪些工作室杭州关键词优化服务
  • 政府无障碍网站建设电商网站订烟平台
  • 橙子建站官网抖音投放网络运营推广具体做什么工作
  • 怎么看网站是哪个公司做的淘宝运营培训课程免费
  • 网站制作器网站seo怎么做
  • 电信200m宽带做网站卡吗全国广告投放平台
  • 淘宝客优惠券网站建设营销策划方案案例
  • 做自己的游戏网站网络营销专业学什么
  • 用dw怎么做酷炫的网站软件外包公司有前途吗
  • lamp网站架构苏州旺道seo
  • 网站数字证书怎么做萧山区seo关键词排名
  • 上海专业网站制作设计专业网络推广公司
  • 政府集约化网站建设建议360优化大师app
  • 淘宝客如何新建网站宁波关键词优化排名工具
  • 住房和城乡建设部网站建筑电工web个人网站设计代码
  • 学校网站模板免费下载站长工具seo综合查询论坛
  • wordpress和django网站建设与优化
  • 西安成品网站建设百度指数怎么看
  • 新市区做网站博客推广的方法与技巧
  • 建设网站一般要多钱百度关键词排名代发
  • 大连网页网站制作网站怎么建设
  • 莱州做网站的公司青岛神马排名优化
  • 呼市品牌网站建设那家好百度在线识图查图片
  • 濮阳网站建设哪家好如何在各大网站发布信息
  • 装修网站怎么做hao123影视