Info
Content

Proxy with LUA

root@test:/etc/nginx/sites-enabled# cat hkproxy 
server { 
  listen 80;
  server_name hkproxy.mushroom-wars.com;

  access_log /var/log/nginx/hkproxy_access.log;
  error_log /var/log/nginx/hkproxy_error.log error;
  
  location / {
    content_by_lua '
      command = "/usr/bin/get-page.sh "..ngx.var.request_uri;
      local handle = io.popen(command);
      local result = handle:read("*a");
      handle:close();
      ngx.print(result);';
  }
}

root@test:/etc/nginx/sites-enabled# cat /usr/bin/get-page.sh 
#!/bin/bash
curl -L https://docs.google.com$@;
root@test:/etc/nginx/sites-enabled# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@test:/etc/nginx/sites-enabled# /etc/init.d/nginx restart
[ ok ] Restarting nginx (via systemctl): nginx.service.
No Comments
Back to top