S
S
softshape2015-03-10 07:35:59
Nginx
softshape, 2015-03-10 07:35:59

How to call phantomjs directly from nginx?

Hello everyone,
I need advice, is it possible and how to configure nginx to solve such a problem -
for each request like www.domain.ru/path/?pdf=12345.pdf, call phantomjs with parameters -

phantomjs /opt/www/modules/pdf/rasterize.js 
'http://www.domain.ru/path/?pdf=12345.pdf' /opt/www/files/12345.pdf A4

In other words, he is
  1. "catches" all URLs with the pdf=... parameter.
  2. calls phantomjs
  3. the name of the output PDF file is taken from the pdf=... parameter.
  4. after that makes a redirect to www.domain.ru/files/12345.pdf

Can this be done at the nginx settings level and how?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
raiboon, 2015-03-10
@raiboon

Choose pearl or lua - and go ahead, any magic you want and everything is inside nginx.

E
Eugene, 2015-03-10
@Nc_Soft

You can proxy the call to a php script that will launch the phantom via exec, and then transfer the return back to nginx via x-accel-redirect. If we also add a proxy cache so that PHP is called only once, then we get a completely viable solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question