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


Server configuration for Node.js application

我正在尝试将应用程序从PHP移动到Node.js。 PHP 应用程序使用 Apache 服务器,并具有应用程序运行所需的tileservices.conf文件。如何将此文件中的配置移动到 Node 应用程序?

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>

已编辑:

关于路由 http://expressjs.com/en/guide/routing.html 的大量信息

对于第一部分(直到第一个 2x 新行)

您几乎需要 Express 来执行以下操作:

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
});

第二部分:

// ^/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
});

第一部分可能不会成为问题,因为 Node.js 不会提供目录和文件,除非您也对其进行编程。因此,您的服务器受到保护。

第二部分,如果这些文件(如图像),您可能需要考虑将它们发送到用户槽节点的方法。如果这些只是页面/其他数据,您将通过Node提供服务,您基本上需要过滤访问它们的IP-s,以便类似于

//    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

可能会有所帮助

可悲的是,我自己不是节点.js专家,因此您需要寻找其他答案或提出更具体的问题来完成所有工作。

希望这一切都对你有所帮助! :)