douqiao5543 2016-04-21 15:26
浏览 160
已采纳

Node.js应用程序的服务器配置

I am trying to move an application off of PHP and onto Node.js. The PHP application uses an Apache server and has a tileservices.conf file that is necessary for the app to work. How would I move over the configuration in this file to a Node application?

Alias /tiles /sandbox/TileServices/www/TileStreamer.php
Alias /thumbs /sandbox/TileServices/www/ThumbStreamer.php
Alias /MosaicTest /sandbox/TileServices/www/MosaicTest

RewriteEngine on
RewriteRule ^/1.0.0/([a-zA-Z0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)\.[a-zA-Z]*$ /sandbox/TileServices/tiles/tc/cache_server.php?z=$2&c=$3&r=$4&cache=$1
RewriteRule ^/nwomtest/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/tc/cache_server_new.php?z=$2&c=$3&r=$4&cache=$1
RewriteRule ^/nocache/nwomtest/1.0.0/(.+)/(.+)/(.+)/(.+)$ /sandbox/TileServices/www/tc/cache_server_new.php?z=$2&c=$3&r=$4&cache=$1&do_not_cache=nocache
RewriteRule ^/nocache/nwomtest/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/tc/cache_server_new.php?z=$2&c=$3&r=$4&cache=$1&do_not_cache=nocache

RewriteRule ^/oms/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/MosaicRequestHandler.php?z=$2&c=$3&r=$4&library=$1&filestyle=strip
RewriteRule ^/omb/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/MosaicRequestHandler.php?z=$2&c=$3&r=$4&library=$1&filestyle=block
RewriteRule ^/ms/1.0.0/(.+)/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/Mosaic/Mosaic.php?z=$3&c=$4&r=$5&resource=$1&tkid=$2&filestyle=strip
RewriteRule ^/mb/1.0.0/(.+)/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/Mosaic/Mosaic.php?z=$3&c=$4&r=$5&resource=$1&tkid=$2&filestyle=block

<Directory "/sandbox/TileServices/www">
    AllowOverride None
    Options -Indexes
    Require all granted

    <IfModule speling>
        CheckSpelling on
    </IfModule>

    SetEnv MOUNT_PREFIX "/mnt/autofs"
</Directory>

<Directory "/sandbox/TileServices/www/tiles/MosaicTest">
    Require all denied
    Allow from 10.0.0.0/8
    Allow from 172.16.0.0/12
    Allow from 192.168.0.0/16
    Allow from 206.90.52.6/32
</Directory>
  • 写回答

1条回答 默认 最新

  • doushichi3678 2016-04-21 15:43
    关注

    Edited:

    //a ton of info on routing http://expressjs.com/en/guide/routing.html

    for the first part (until first 2x new line)

    you pretty much need express to do the following:

    app.get('/tiles', function (req, res) {
      res.send('GET request to /tiles'); //or some other logic
    });
    app.get('/thumbs', function (req, res) {
      res.send('GET request to /tiles'); //or some other logic
    });
    app.get('/MosaicTest', function (req, res) {
      res.send('GET request to /tiles'); //or some other logic
    });
    

    Second part:

    // ^/1.0.0/([a-zA-Z0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)\.[a-zA-Z]*$
    
    app.get('/1.0.0/:param1/:param2/:param3/:param4', function (req, res) {
      var param1 =req.params.param1,
       param2 = req.params.param2,
       param3 = req.params.param3,
       param4 = req.params.param4;
    
      res.send('your first route parameter is '+param1); //or some other logic
    });
    

    First part will probably not be a problem becase Node.js will NOT serve directories and files unless you program it too. So your server is protected.

    Second part if those are files (like images) you probably need to think of way to send those to the user trough node. If those are just pages/other data you will serve trough Node you basically need to filter the IP-s that access them so something along the lines of

    //    this goes after your route definition
    // so after something like app.get('/MosaicTest', function (req, res) { 
    var ip = req.ip; 
    if (ip == '127.0.0.1') {
        res.send('ip not allowed');
        res.end();
    }
    // close route definition });
    // source: http://stackoverflow.com/questions/12349251/restrict-access-to-node-js-based-http-server-by-ip-address
    

    might help

    Sadly I am no node.js expert myself so you will need to look for other answers or ask more specific questions to get it all done.

    Hope it all helps you on your way! :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置