GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Nginx::Simple(3) User Contributed Perl Documentation Nginx::Simple(3)
 

Nginx::Simple - Easy to use interface for "--with-http_perl_module"

  nginx.conf:  
    perl_modules perl;
    perl_require Test.pm;
    server {
       listen       80;
       server_name  localhost;
       location / {
          perl Test::handler; # always enter package::handler
       }
    }
  Test.pm:
    package Test;
    use Nginx::Simple;
    # (optional) triggered before main is run
    sub init
    {
        my $self = shift;
        $self->{user} = 'stinky_pete';
    }
    # automatically dispatches here
    sub main
    {
        my $self = shift;
        
        $self->header_set('Content-Type' => 'text/html');
        $self->print('rock on!');
        $self->print("$self->{user} is using the system");
        
        $self->log('I found a rabbit...');
        
        my $something = $self->param("here");
        $self->print("I found $something...");
    }
    # (optional) triggered after main is run
    sub cleanup
    {
        my $self = shift;
        # do something?
    }
    # (optional) triggered on a server error (otherwise returns a normal 500 error)
    sub error
    {
        my $self = shift;
        my $error = shift;
        $self->status(500);
        $self->print("oh, uh, there is an error! ($error)");
    }

$self->server
Returns the nginx server object.
$self->uri
Returns the uri.
$self->filename
Returns the path filename.
$self->request_method
Returns the request_method.
$self->remote_addr
Returns the remote_addr.
$self->header_in
Return value of header_in.
$self->print(...)
Output via http.
$self->auto_header
Returns true if set, otherwise args 1 sets true and 0 false.
$self->dispatching
Returns true if we're dispatching actively.
$self->header_set('header_type', 'value')
Set output header.
$self->header('content-type')
Set content type.
$self->headers
Returns hashref of headers.
$self->location('url')
Redirect to a url.
$self->status(...)
Set output status... (200, 404, etc...) If no argument given, returns status.
$self->param(...)
Return a parameter passed via CGI--works like CGI::param.
$self->param_hash
Return a friendly hashref of CGI parameters.
$self->request_body & $self->request
Returns request body.
$self->args
Returns args.
process_auto_header
Process the autoheader.
error_stack
Returns the "error stack" as an array.
get_error
Returns error as string.
$self->unescape
Unscape HTTP URI encoding.
$self->cookie
Cookie methods:
   $self->cookie->set(-name => 'foo', -value => 'bar');
   my %cookies = $self->cookie->read;
$self->elapsed_time
Returns elapsed time since initial dispatch.

Michael J. Flickinger, "<mjflick@gnu.org>"

You may distribute under the terms of either the GNU General Public License or the Artistic License.
2011-02-18 perl v5.28.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.