V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
monway
V2EX  ›  Python

请教大佬们关于使用 Python 在服务器上拦截请求的问题

  •  
  •   monway · 2018-01-31 17:57:06 +08:00 · 3038 次点击
    这是一个创建于 2293 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想实现的是: 服务器上安装的是 Nginx 或 Apache 提供 web 服务,我想在服务器上执行一个 Python 的脚本拦截用户请求的 Http 数据包。然后修改在发给容器,容器在返回给客户。请问大佬们 Python 可以实现吗?

    8 条回复    2018-02-04 03:52:33 +08:00
    ysc3839
        1
    ysc3839  
       2018-01-31 18:11:08 +08:00
    可以,就是个反向代理
    cloverstd
        2
    cloverstd  
       2018-01-31 18:11:49 +08:00
    1. 用你的 Python 脚本替换 Nginx
    2. Nginx 到你的 Python 脚本,你的脚本再到后端服务
    3. 如果不能动 Nginx 可以用 iptables 实现 1
    owenliang
        3
    owenliang  
       2018-01-31 18:13:19 +08:00
    做个代理服务倒是可以,想不侵入的拦截是不容易实现的。
    bfpiaoran
        4
    bfpiaoran  
       2018-01-31 18:16:59 +08:00 via Android
    用 mitmproxy
    0ZXYDDu796nVCFxq
        5
    0ZXYDDu796nVCFxq  
       2018-01-31 18:48:44 +08:00 via iPhone
    性能很感人,最好先评估一下流量
    zjb861107
        6
    zjb861107  
       2018-01-31 19:43:42 +08:00
    用 verynginx 试试?需求不是特别复杂的话,也许并不需要 python。。。
    knightdf
        7
    knightdf  
       2018-01-31 19:51:29 +08:00
    你需要 nginx-lua
    fakepoet
        8
    fakepoet  
       2018-02-04 03:52:33 +08:00
    感觉你需要这个 http://openresty.org/cn/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1070 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:56 · PVG 02:56 · LAX 11:56 · JFK 14:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.