博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用nginx向现有网站添加登录验证功能(不添加修改现有网站代码)
阅读量:4618 次
发布时间:2019-06-09

本文共 1104 字,大约阅读时间需要 3 分钟。

在不改变现有网站代码的前提下加入验证功能:
1.假设现有网站后端nodejs,端口3000,nginx配置如下
server {        listen      80;        server_name localhost;        location /{            proxy_pass  http://localhost:3000;        } }
2.现在要为该网站添加验证功能,在不改变原有代码基础上需要做如下工作:
a.首先需要为nginx加入http_auth_request模块(附件),若nginx版本1.5.4+则无需添加该模块
b.新建node.js express网站,端口3001,并添加登录验证功能:
c.修改nginx配置文件如下:
server {             listen 80;            server_name localhost;            location /{                 auth_request /auth;                 proxy_pass http://localhost:3000;             }             location /auth{                 proxy_pass http://localhost:3001;                proxy_pass_request_body off;                 proxy_set_header Content-Length "";                 proxy_set_header X-Original-URI $request_uri;             }             location /login{                 proxy_pass http://localhost:3001;            }             error_page 403 /login;        }

原理:访问80端口,先由auth_request将request送至/auth验证请求,如果是验证了的则返回200,nginx继续将请求发送至3000端口,如果/auth返回403,则nginx不会将请求发送至3000端口,最后定义一下403的位置即可。

转载于:https://www.cnblogs.com/hao-dotnet/p/3477442.html

你可能感兴趣的文章
Python加密与解密
查看>>
C++在Ubuntu上编译mysql问题
查看>>
Java学习--Cookie 和session
查看>>
rem布局在webview中页面错乱
查看>>
第12章:MongoDB-CRUD操作--文档--查询--游标详解
查看>>
C语言中环境变量操作
查看>>
[codeforces 519E]E. A and B and Lecture Rooms(树上倍增)
查看>>
SQL语句中的output
查看>>
jquery之过滤filter,not
查看>>
Ci 自己的分页类【原创】
查看>>
JavaScript编写自己的比特币交易代码
查看>>
THE START OF ASE
查看>>
使用mongodump及mongorestore备份及恢复数据
查看>>
Ch07 包和引入 - 练习
查看>>
变形属性 transform
查看>>
黑马程序员----java基础:多线程
查看>>
Quartz 2D 绘图
查看>>
Scrapy源代码分析-经常使用的爬虫类-CrawlSpider(三)
查看>>
ZOJ Problem Set - 3820 Building Fire Stations 【树的直径 + 操作 】
查看>>
Tomcat 隐藏Server Name
查看>>