You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 11, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+140Lines changed: 140 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,136 @@ Lua is a lightweight, high-level, multi-paradigm programming language designed p
61
61
- Extra Lua Modules.
62
62
- Performance Benchmarks.
63
63
64
+
## Typical Uses
65
+
66
+
Just to name a few:
67
+
68
+
* Mashup'ing and processing outputs of various Nginx upstream outputs (proxy, drizzle, postgres, redis, memcached, and etc) in Lua,
69
+
* doing arbitrarily complex access control and security checks in Lua before requests actually reach the upstream backends,
70
+
* manipulating response headers in an arbitrary way (by Lua)
71
+
* fetching backend information from external storage backends (like redis, memcached, mysql, postgresql) and use that information to choose which upstream backend to access on-the-fly,
72
+
* coding up arbitrarily complex web applications in a content handler using synchronous but still non-blocking access to the database backends and other storage,
73
+
* doing very complex URL dispatch in Lua at rewrite phase,
74
+
* using Lua to implement advanced caching mechanism for Nginx's subrequests and arbitrary locations.
75
+
76
+
The possibilities are unlimited as the module allows bringing together various
77
+
elements within Nginx as well as exposing the power of the Lua language to the
78
+
user. The module provides the full flexibility of scripting while offering
79
+
performance levels comparable with native C language programs both in terms of
80
+
CPU time as well as memory footprint thanks to LuaJIT 2.x.
81
+
82
+
Other scripting language implementations typically struggle to match this
83
+
performance level.
84
+
85
+
## How to use this image
86
+
87
+
### Hosting some simple static content
88
+
89
+
```console
90
+
$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
91
+
```
92
+
Alternatively, a simple `Dockerfile` can be used to generate a new image that includes the necessary content (which is a much cleaner solution than the bind mount above):
93
+
```dockerfile
94
+
FROM nginx
95
+
COPY static-html-directory /usr/share/nginx/html
96
+
```
97
+
Place this file in the same directory as your directory of content ("static-html-directory"), run `docker build -t some-content-nginx .`, then start your container:
98
+
```console
99
+
$ docker run --name some-nginx -d some-content-nginx
100
+
```
101
+
102
+
### Exposing external port
103
+
104
+
```console
105
+
$ docker run --name some-nginx -d -p 8080:80 some-content-nginx
106
+
```
107
+
Then you can hit `http://localhost:8080` or `http://host-ip:8080` in your browser.
108
+
109
+
### Complex configuration
110
+
111
+
```console
112
+
$ docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
113
+
```
114
+
For information on the syntax of the nginx configuration files, see [the official documentation](http://nginx.org/en/docs/) (specifically the [Beginner's Guide](http://nginx.org/en/docs/beginners_guide.html#conf_structure)).
115
+
If you wish to adapt the default configuration, use something like the following to copy it from a running nginx container:
This can also be accomplished more cleanly using a simple `Dockerfile` (in `/host/path/`):
122
+
```dockerfile
123
+
FROM nginx
124
+
COPY nginx.conf /etc/nginx/nginx.conf
125
+
```
126
+
If you add a custom `CMD` in the Dockerfile, be sure to include `-g daemon off;` in the `CMD` in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!
127
+
Then build the image with `docker build -t custom-nginx .` and run it as follows:
128
+
```console
129
+
$ docker run --name my-custom-nginx-container -d custom-nginx
130
+
```
131
+
#### Using environment variables in nginx configuration (new in 1.19)
132
+
133
+
Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But this image has a function, which will extract environment variables before nginx starts.
134
+
Here is an example using docker-compose.yml:
135
+
```yaml
136
+
web:
137
+
image: nginx
138
+
volumes:
139
+
- ./templates:/etc/nginx/templates
140
+
ports:
141
+
- "8080:80"
142
+
environment:
143
+
- NGINX_HOST=foobar.com
144
+
- NGINX_PORT=80
145
+
```
146
+
By default, this function reads template files in `/etc/nginx/templates/*.template` and outputs the result of executing `envsubst` to `/etc/nginx/conf.d`.
147
+
So if you place `templates/default.conf.template` file, which contains variable references like this:
148
+
listen ${NGINX_PORT};
149
+
outputs to `/etc/nginx/conf.d/default.conf` like this:
150
+
listen 80;
151
+
This behavior can be changed via the following environment variables:
152
+
- `NGINX_ENVSUBST_TEMPLATE_DIR`
153
+
- A directory which contains template files (default: `/etc/nginx/templates`)
154
+
- When this directory doesn't exist, this function will do nothing about template processing.
155
+
- `NGINX_ENVSUBST_TEMPLATE_SUFFIX`
156
+
- A suffix of template files (default: `.template`)
157
+
- This function only processes the files whose name ends with this suffix.
158
+
- `NGINX_ENVSUBST_OUTPUT_DIR`
159
+
- A directory where the result of executing envsubst is output (default: `/etc/nginx/conf.d`)
160
+
- The output filename is the template filename with the suffix removed.
161
+
- ex.) `/etc/nginx/templates/default.conf.template` will be output with the filename `/etc/nginx/conf.d/default.conf`.
162
+
- This directory must be writable by the user running a container.
163
+
164
+
### Running nginx in read-only mode
165
+
166
+
To run nginx in read-only mode, you will need to mount a Docker volume to every location where nginx writes information. The default nginx configuration requires write access to `/var/cache` and `/var/run`. This can be easily accomplished by running nginx as follows:
If you have a more advanced configuration that requires nginx to write to other locations, simply add more volume mounts to those locations.
171
+
172
+
### Running nginx in debug mode
173
+
174
+
Images since version 1.9.8 come with `nginx-debug` binary that produces verbose output when using higher log levels. It can be used with simple CMD substitution:
Similar configuration in docker-compose.yml may look like this:
179
+
```yaml
180
+
web:
181
+
image: nginx
182
+
volumes:
183
+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
184
+
command: [nginx-debug, '-g', 'daemon off;']
185
+
```
186
+
187
+
### Entrypoint quiet logs
188
+
189
+
Since version 1.19.0, a verbose entrypoint was added. It provides information on what's happening during container startup. You can silence this output by setting environment variable `NGINX_ENTRYPOINT_QUIET_LOGS`:
190
+
```console
191
+
$ docker run -d -e NGINX_ENTRYPOINT_QUIET_LOGS=1 nginx
192
+
```
193
+
64
194
## Specs
65
195
66
196
- [nginx](https://nginx.org/en/download.html)
@@ -300,6 +430,16 @@ More details about the benchark can be found in [docs/benchmarks/different_image
300
430
301
431
More details about the benchark can be found in [docs/benchmarks/distros](docs/benchmarks/distros).
302
432
433
+
## Extras
434
+
435
+
Extract of [openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module) under [BSD license](https://github.com/openresty/lua-nginx-module#copyright-and-license).
436
+
437
+
- [LUA Nginx Module - Known Issues](docs/lua-nginx-module/known-issues.md)
0 commit comments