doc: examples
This commit is contained in:
parent
73df84bd6e
commit
026fe8757e
6
doc/examples/README.md
Normal file
6
doc/examples/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Examples
|
||||
|
||||
- [simple static site](basic/README.md)
|
||||
- [static site with templates](static-template/README.md)
|
||||
- [print env via NJS](njs/README.md)
|
||||
- [print env via Perl](perl/README.md)
|
8
doc/examples/basic/Dockerfile
Normal file
8
doc/examples/basic/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
COPY /static/ /etc/angie/static/
|
||||
|
||||
## not necessary at all - just disables ngx_http_proxy_module configuration
|
||||
ENV NGX_HTTP_NO_PROXY=1
|
20
doc/examples/basic/README.md
Normal file
20
doc/examples/basic/README.md
Normal file
@ -0,0 +1,20 @@
|
||||
# simple static site
|
||||
|
||||
configuration:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 8080;
|
||||
}
|
||||
```
|
||||
|
||||
Dockerfile:
|
||||
|
||||
```dockerfile
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
COPY /static/ /etc/angie/static/
|
||||
```
|
||||
|
||||
both are simple and fine enough.
|
3
doc/examples/basic/site/http-site.conf
Normal file
3
doc/examples/basic/site/http-site.conf
Normal file
@ -0,0 +1,3 @@
|
||||
server {
|
||||
listen 8080;
|
||||
}
|
5
doc/examples/basic/static/index.html
Normal file
5
doc/examples/basic/static/index.html
Normal file
@ -0,0 +1,5 @@
|
||||
<hmtl>
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
</body>
|
||||
</hmtl>
|
11
doc/examples/njs/Dockerfile
Normal file
11
doc/examples/njs/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
|
||||
## install 'angie-module-njs' and process package contents
|
||||
RUN apt-install-angie-mod.sh njs ; \
|
||||
apt-clean.sh
|
||||
|
||||
## load ngx_http_js_module
|
||||
ENV NGX_HTTP_MODULES='njs'
|
54
doc/examples/njs/README.md
Normal file
54
doc/examples/njs/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# print env via NJS
|
||||
|
||||
configuration:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
location / { return 204; }
|
||||
|
||||
js_import ngx_env.js;
|
||||
location = /env
|
||||
{
|
||||
js_content ngx_env.report;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
NJS script:
|
||||
|
||||
```js
|
||||
function report(r) {
|
||||
var s = "";
|
||||
const keys = Object.keys(process.env).sort();
|
||||
for (const i in keys) {
|
||||
const k = keys[i];
|
||||
const v = process.env[k];
|
||||
s += k + '=' + v + "\n";
|
||||
}
|
||||
r.return(200, s);
|
||||
}
|
||||
|
||||
export default { report };
|
||||
```
|
||||
|
||||
Dockerfile:
|
||||
|
||||
```dockerfile
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
|
||||
## install 'angie-module-njs' and process package contents
|
||||
RUN apt-install-angie-mod.sh njs ; \
|
||||
apt-clean.sh
|
||||
|
||||
## load ngx_http_js_module
|
||||
ENV NGX_HTTP_MODULES='njs'
|
||||
```
|
||||
|
||||
Test URI e.g. with `curl`:
|
||||
```sh
|
||||
curl http://127.0.0.1:8080/env
|
||||
```
|
11
doc/examples/njs/site/http-env-js.conf
Normal file
11
doc/examples/njs/site/http-env-js.conf
Normal file
@ -0,0 +1,11 @@
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
location / { return 204; }
|
||||
|
||||
js_import ngx_env.js;
|
||||
location = /env
|
||||
{
|
||||
js_content ngx_env.report;
|
||||
}
|
||||
}
|
12
doc/examples/njs/site/ngx_env.js
Normal file
12
doc/examples/njs/site/ngx_env.js
Normal file
@ -0,0 +1,12 @@
|
||||
function report(r) {
|
||||
var s = "";
|
||||
const keys = Object.keys(process.env).sort();
|
||||
for (const i in keys) {
|
||||
const k = keys[i];
|
||||
const v = process.env[k];
|
||||
s += k + '=' + v + "\n";
|
||||
}
|
||||
r.return(200, s);
|
||||
}
|
||||
|
||||
export default { report };
|
11
doc/examples/perl/Dockerfile
Normal file
11
doc/examples/perl/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
|
||||
## install 'angie-module-perl' and process package contents
|
||||
RUN apt-install-angie-mod.sh perl ; \
|
||||
apt-clean.sh
|
||||
|
||||
## load ngx_http_perl_module
|
||||
ENV NGX_HTTP_MODULES='perl'
|
64
doc/examples/perl/README.md
Normal file
64
doc/examples/perl/README.md
Normal file
@ -0,0 +1,64 @@
|
||||
# print env via Perl
|
||||
|
||||
configuration:
|
||||
|
||||
```nginx
|
||||
perl_require ngx_env.pm;
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
location / { return 204; }
|
||||
|
||||
location = /env
|
||||
{
|
||||
perl ngx_env::report;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Perl script:
|
||||
|
||||
```perl
|
||||
package ngx_env;
|
||||
|
||||
use nginx;
|
||||
|
||||
sub report {
|
||||
my $r = shift;
|
||||
|
||||
my $s = "";
|
||||
for (sort keys %ENV) {
|
||||
$s = $s . "$_=$ENV{$_}\n";
|
||||
}
|
||||
|
||||
$r->discard_request_body;
|
||||
$r->send_http_header;
|
||||
$r->print($s);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
```
|
||||
|
||||
Dockerfile:
|
||||
|
||||
```dockerfile
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
|
||||
## install 'angie-module-perl' and process package contents
|
||||
RUN apt-install-angie-mod.sh perl ; \
|
||||
apt-clean.sh
|
||||
|
||||
## load ngx_http_perl_module
|
||||
ENV NGX_HTTP_MODULES='perl'
|
||||
```
|
||||
|
||||
Test URI e.g. with `curl`:
|
||||
```sh
|
||||
curl http://127.0.0.1:8080/env
|
||||
```
|
11
doc/examples/perl/site/http-env-perl.conf
Normal file
11
doc/examples/perl/site/http-env-perl.conf
Normal file
@ -0,0 +1,11 @@
|
||||
perl_require ngx_env.pm;
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
location / { return 204; }
|
||||
|
||||
location = /env
|
||||
{
|
||||
perl ngx_env::report;
|
||||
}
|
||||
}
|
22
doc/examples/perl/site/ngx_env.pm
Normal file
22
doc/examples/perl/site/ngx_env.pm
Normal file
@ -0,0 +1,22 @@
|
||||
package ngx_env;
|
||||
|
||||
use nginx;
|
||||
|
||||
sub report {
|
||||
my $r = shift;
|
||||
|
||||
my $s = "";
|
||||
for (sort keys %ENV) {
|
||||
$s = $s . "$_=$ENV{$_}\n";
|
||||
}
|
||||
|
||||
$r->discard_request_body;
|
||||
$r->send_http_header;
|
||||
$r->print($s);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
8
doc/examples/static-template/Dockerfile
Normal file
8
doc/examples/static-template/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
COPY /static/ /etc/angie/static/
|
||||
|
||||
## instruct entrypoint to process static/ - unroll *.j2 templates, etc.
|
||||
ENV NGX_PROCESS_STATIC=1
|
34
doc/examples/static-template/README.md
Normal file
34
doc/examples/static-template/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
# static site with templates
|
||||
|
||||
mostly same as [simple static site](../basic/README.md) except environment variable `NGX_PROCESS_STATIC=1`.
|
||||
|
||||
configuration:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 8080;
|
||||
}
|
||||
```
|
||||
|
||||
Dockerfile:
|
||||
|
||||
```dockerfile
|
||||
FROM docker.io/rockdrilla/angie-conv:v0.0.1
|
||||
|
||||
COPY /site/ /etc/angie/site/
|
||||
COPY /static/ /etc/angie/static/
|
||||
|
||||
## instruct entrypoint to process static/ - unroll *.j2 templates, etc.
|
||||
ENV NGX_PROCESS_STATIC=1
|
||||
```
|
||||
|
||||
Also note that there's no `index.html` but `index.html.j2`:
|
||||
|
||||
```jinja
|
||||
<hmtl>
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
This image is powered by Angie {{ env.ANGIE_VERSION }} and Python {{ env.PYTHON_VERSION }}.
|
||||
</body>
|
||||
</hmtl>
|
||||
```
|
3
doc/examples/static-template/site/http-site.conf
Normal file
3
doc/examples/static-template/site/http-site.conf
Normal file
@ -0,0 +1,3 @@
|
||||
server {
|
||||
listen 8080;
|
||||
}
|
6
doc/examples/static-template/static/index.html.j2
Normal file
6
doc/examples/static-template/static/index.html.j2
Normal file
@ -0,0 +1,6 @@
|
||||
<hmtl>
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
This image is powered by Angie {{ env.ANGIE_VERSION }} and Python {{ env.PYTHON_VERSION }}.
|
||||
</body>
|
||||
</hmtl>
|
Loading…
Reference in New Issue
Block a user