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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog