Welcome! Log In Create A New Profile

Advanced

Re: quick start on writing a module?

Piotr Sikora
June 16, 2010 11:20AM
Hi,
Maxim already answered most of your questions regarding writing a module
like this from scratch. I would like to add that you can already do this,
without writing new module, by misusing Maxim's excellent
ngx_http_auth_request_module [1] and ngx_postgres [2].

There are two "but":
1) Required "postgres_set" directive is still available only in my local
repository. I intend to push it to GitHub today or tomorrow, after adding
some test cases, so stay tuned :)
2) You need to use "proxy_pass" for now. Ideally, you should create your own
mini-module that would serve static files based on complex_value
($location). This should be mostly copy & paste of "ngx_http_static_handler"
from nginx's ngx_http_static_module.c.

[1] http://mdounin.ru/hg/ngx_http_auth_request_module/
[2] http://labs.frickle.com/nginx_ngx_postgres/

Best regards,
Piotr Sikora < piotr.sikora@frickle.com >


--- configuration ---
upstream pgsql {
postgres_server 127.0.0.1 dbname=test user=test password=test;
}

server {
listen 80;

location = /auth {
internal;
postgres_pass pgsql;
postgres_query "SELECT 'c-d', '123456', '0.1', '/etc/passwd'";
postgres_set $pg_disposition 0 0 required;
postgres_set $pg_etag 0 1 required;
postgres_set $pg_version 0 2 required;
postgres_set $pg_location 0 3 required;
}

location / {
auth_request /auth;
auth_request_set $disposition $pg_disposition;
auth_request_set $etag $pg_etag;
auth_request_set $version $pg_version;
auth_request_set $location $pg_location;
add_header "Content-Disposition" $disposition;
add_header "Etag" $etag;
add_header "X-mod_asset-version" $version;
proxy_pass http://127.0.0.1:81/$location;
}
}

# proxy for serving static files
server {
listen 81;

location / {
root /;
}
}


--- output ---
$ curl -v http://localhost/
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.5
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/0.8.41
< Date: Wed, 16 Jun 2010 16:55:30 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 3078
< Last-Modified: Sat, 15 May 2010 01:27:40 GMT
< Accept-Ranges: bytes
< Content-Disposition: c-d
< Etag: 123456
< X-mod_asset-version: 0.1
<
root:*:0:0:Charlie &:/root:/bin/ksh
(..)



_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

quick start on writing a module?

Mark Harrison June 16, 2010 05:34AM

Re: quick start on writing a module?

Maxim Dounin June 16, 2010 06:48AM

Re: quick start on writing a module?

Piotr Sikora June 16, 2010 11:20AM

Re: quick start on writing a module?

Maxim Dounin June 16, 2010 11:34AM

Re: quick start on writing a module?

Piotr Sikora June 16, 2010 11:54AM

Re: quick start on writing a module?

Maxim Dounin June 16, 2010 12:32PM

Re: quick start on writing a module?

Piotr Sikora June 16, 2010 12:52PM

Re: quick start on writing a module?

Maxim Dounin June 16, 2010 01:32PM

Re: quick start on writing a module?

Piotr Sikora June 16, 2010 01:52PM

Re: quick start on writing a module?

Piotr Sikora June 16, 2010 01:48PM

Re: quick start on writing a module?

agentzh June 16, 2010 10:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 223
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready