![]() |
ReverseProxy is a component that sits in front of web server(s) or app server(s), and routes requests to the corresponding server based on configuration. The advantage of this approach is:
Using apache or even lighttpd for reverse proxy seems overkill. On nslu2 with optware, pound and nginx are two lightweight reverse proxy servers. Pound is strictly a "reverse proxy and load balancer", while nginx can also connect to upstream (backend) PHP server with fastcgi protocol and serve static content. It makes a lot of sense to use nginx on the slug, especially in the following scenarios:
Let's say we want to test nginx (localhost:7007) in front of cherokee (localhost:8008, an example of http web/app server) and PHP (localhost:9009, an example of fastcgi). PreparationInstall cherokee and php-fcgi # ipkg update # ipkg install cherokee # ipkg install php-fcgi
Verify php-fcgi version # /opt/bin/php-fcgi -v PHP 5.1.6 (cgi-fcgi) (built: Aug 25 2006 08:50:32) ... Prepare a simple info.php, with just a single line of # mkdir -p /opt/share/www/php # echo "<?php phpinfo(); ?>" > /opt/share/www/phpinfo.php Install, config & test nginx.Basic setup Change Launch nginx
Add cherokeeAdd the following lines to /opt/nginx/conf/nginx.conf http server section: location /cherokee/ {
proxy_pass http://127.0.0.1:8008/;
proxy_redirect default;
}
Bounce nginx
Add php-fcgiAdd the following lines to location ~ \.php$ {
fastcgi_pass 127.0.0.1:9009;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/share/www/php/$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
Launching php-fcgi Bounce nginx
Tighten securityTry to run PHP or app server as non-root, and only pass certain environment variables to PHP. See reference. References
UpdateIn order to be able to run nginx successfull (if you install nginx only) you need also to install: zlib openssl pcre libstdc++ please use ipkg install zlib (and the name of the other components previously listed) CIAO |