简体   繁体   中英

Server configuration for Node.js application

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>

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! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM