Re: redirect based on file content

2018-07-16 Thread Dmitry Volyntsev

You can try to use njs here:

http://nginx.org/en/docs/http/ngx_http_js_module.html
http://nginx.org/en/docs/njs/njs_api.html#http - more about r object.

nginx.conf:
http {
js_include http.njs;
...
server {
listen 9000;
location / {
js_content redirect;
}
}
}

http.njs:
function redirect(r) {
var fs = require('fs');
var body = fs.readFileSync('/redirects/' + r.uri);
var parts = body.split(' ');
var code = Number(parts[0]);
var uri = parts[1];

r.return(code, uri);
}


On 16.07.2018 17:38, Torsten Curdt wrote:
I want to have files in the filesystem that specify the response code 
and redirect location instead of relying on the nginx configuration for it.


Imagine a file foo.ext looking like:

   301 https://some.host.com/foo.bla

On a GET of foo.ext it should result in a 301 to 
https://some.host.com/foo.bla


So far I haven't found a module for this. I presume it should not be too 
terribly hard to write a module for it but maybe I missed something? So 
I thought I rather double check if there is an easier route.


Any thoughts?

cheers,
Torsten


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: redirect based on file content

2018-07-16 Thread itpp2012
This can be done with Lua but each disk access is a blocking call to nginx,
your design should include caching of such calls (access disk once every 100
calls or after 60 seconds).

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,280529,280533#msg-280533

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


redirect based on file content

2018-07-16 Thread Torsten Curdt
I want to have files in the filesystem that specify the response code and
redirect location instead of relying on the nginx configuration for it.

Imagine a file foo.ext looking like:

  301 https://some.host.com/foo.bla

On a GET of foo.ext it should result in a 301 to
https://some.host.com/foo.bla

So far I haven't found a module for this. I presume it should not be too
terribly hard to write a module for it but maybe I missed something? So I
thought I rather double check if there is an easier route.

Any thoughts?

cheers,
Torsten
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx