dongmen5867 2017-06-02 11:31
浏览 69
已采纳

将单独的REST路由从PHP迁移到Node.js / Golang /等等

At this moment my REST API works on PHP, and is running behind Apache2/Nginx (on Apache2 actually, migration to Nginx is in progress), but after reading about Golang and Node.js performance for rest, i am thinking about migrating my REST from PHP to one of this variants, but where i stuck is how to migrate only some of routes, not whole REST at one.

For example now i have two routes

/users and /articles

apache is listening for 80 port, and then with PHP help return response for them, but what if i want to migrate /articles to Node.js? How my webserver will know what for /articles he need to call Node.js if Node.js will be on different port, but for /users still use PHP?

  • 写回答

2条回答 默认 最新

  • doucong1992 2017-06-02 13:03
    关注

    Found pretty good solution from my colleagues, just handle request with nginx and redirect to another server if request uri contains something, like this:

    server {
        listen 127.0.0.1:80;
        server_name localhost.dev;
        location ~* ^/[a-zA-Z0-9]+_[a-zA-Z0-9]+_(?<image_id>[0-9]+).* {
            include             proxy_headers.conf;
            proxy_set_header    X-Secure     False;
            add_header          X-Image-Id   $image_id;
            access_log          off;
            proxy_pass http://localhost-image-cache;
            proxy_next_upstream off;
        }
    }
    
    upstream localhost-image-cache {
    hash $server_name$image_id consistent;
        server 127.0.0.1:81 max_fails=0;
        keepalive 16;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 第一天重装配置python和opencv后第二天打开就成这样,瞎捣鼓搞出来文件夹还是没法联网
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥100 AT89C52单片机C语言调试之后再回答
  • ¥15 AT89C52单片机C语言串口助手发送数据包返回值
  • ¥15 C++数组中找第二小的数字程序纠错
  • ¥50 MATLAB APP 制作出现问题
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e