|
2 | 2 |
|
3 | 3 | ## Implementation |
4 | 4 |
|
5 | | -NOTES: |
6 | | - - The following implementation steps have been developed and tested using this [Docker image](https://github.com/fabiocicerchia/nginx-lua). |
7 | | - - The following example uses `./usr/queueit` as the base path for storing all the Queue-it related files. Review and modify it to your needs. |
| 5 | +NOTE: The following implementation steps have been developed and tested using this [Docker image](https://github.com/fabiocicerchia/nginx-lua). |
8 | 6 |
|
| 7 | +Copy [KnownUserNginxHandler.lua](https://github.com/queueit/KnownUser.V3.Lua/blob/master/Handlers/KnownUserNginxHandler.lua) and folders ([SDK](https://github.com/queueit/KnownUser.V3.Lua/tree/master/SDK) and [Helpers](https://github.com/queueit/KnownUser.V3.Lua/tree/master/Helpers)) incl. their content to your NGINX filesystem (in the following example we have added it to `usr/queueit`). |
9 | 8 |
|
10 | | -### 1. Copy the necessary files to your NGINX filesystem |
11 | | - |
12 | | -Copy the following two folders from this repository to your NGINX filesystem: |
13 | | -- [SDK](https://github.com/queueit/KnownUser.V3.Lua/tree/master/SDK) -> `./usr/queueit/SDK` |
14 | | -- [Helpers](https://github.com/queueit/KnownUser.V3.Lua/tree/master/Helpers) -> `./usr/queueit/Helpers` |
15 | | - |
16 | | -Copy the main handler script: |
17 | | - |
18 | | -- [Handlers/KnownUserNginxHandler.lua](https://github.com/queueit/KnownUser.V3.Lua/blob/master/Handlers/KnownUserNginxHandler.lua) -> `./usr/queueit/KnownUserNginxHandler.lua` |
19 | | - |
20 | | - |
21 | | -### 2. Update the package paths |
22 | | - |
23 | | -Update or add the `lua_package_path` configuration option in the `http` section of your main configuration file (typically `nginx.conf`) to include the new paths you created in Step 1. Make sure to keep `;;` in the end which means default path: |
| 9 | +Then update/add `lua_package_path` in your `nginx.conf` to include the new path (keep `;;` in the end which means default path): |
24 | 10 |
|
25 | 11 | ``` |
26 | 12 | http { |
27 | 13 | lua_package_path "./usr/queueit/?.lua;./usr/queueit/SDK/?.lua;./usr/queueit/Helpers/?/?.lua;;"; |
28 | 14 | } |
29 | 15 | ``` |
30 | 16 |
|
31 | | - |
32 | | -### 3. Add the Queue-it handler to a specific location |
33 | | - |
34 | | -Update the configuration file relative to the location you want to be protected by Queue-it (`conf.d/default.conf` or similar): |
35 | | - |
36 | | - ``` |
37 | | - server { |
38 | | - location / { |
39 | | - rewrite_by_lua_block { |
40 | | - local customerId = "{CUSTOMER_ID}" |
41 | | - local secretKey = "{SECRET_KEY}" |
42 | | - |
43 | | - -- Basic example where integration configuration file is loaded from disk. |
44 | | - -- You will need to decide where to store and load this file (caching layer, database ect.). |
45 | | - -- Remember this will be done on all requests, so the selected option must be fast (not causing bottlenecks). |
46 | | - local integrationConfigFilePath = "./usr/queueit/integrationconfig.json" |
47 | | - local integrationConfigFile = io.open(integrationConfigFilePath, "r") |
48 | | - local integrationConfigJson = integrationConfigFile:read("*a") |
49 | | - integrationConfigFile:close() |
50 | | - |
51 | | - local qit = require("KnownUserNginxHandler") |
52 | | - |
53 | | - -- If you want to enable secure or http only cookie settings then change options below. |
54 | | - -- httpOnly: Only enable if you use pure server-side integration e.g. not JS Hybrid. |
55 | | - -- secure: Only enable if your website runs purely on https. |
56 | | - qit.setOptions({ httpOnly = false, secure = false }) |
57 | | - |
58 | | - qit.handleByIntegrationConfig(customerId, secretKey, integrationConfigJson) |
59 | | - } |
| 17 | +Then update `conf.d/default.conf`: |
| 18 | +``` |
| 19 | +server { |
| 20 | + location / { |
| 21 | + rewrite_by_lua_block { |
| 22 | + local customerId = "{CUSTOMER_ID}" |
| 23 | + local secretKey = "{SECRET_KEY}" |
| 24 | +
|
| 25 | + -- Basic example where integration configuration file is loaded from disk. |
| 26 | + -- Please use this for testing / PoC etc., e.g. not on production environment. |
| 27 | + -- For production / final integration you need to decide where to store and load this file. |
| 28 | + -- Could be a caching layer, environment variable, database ect. |
| 29 | + -- It's important that the selected option is fast, |
| 30 | + -- not causing any performance bottlenecks because the file would be loaded on each request. |
| 31 | + local integrationConfigFilePath = "./usr/queueit/integrationconfig.json" |
| 32 | + local integrationConfigFile = io.open(integrationConfigFilePath, "rb") |
| 33 | + local integrationConfigJson = integrationConfigFile:read("*all") |
| 34 | + integrationConfigFile:close() |
| 35 | +
|
| 36 | + local qit = require("KnownUserNginxHandler") |
| 37 | +
|
| 38 | + -- If you want to enable secure or http only cookie settings then change options below. |
| 39 | + -- httpOnly: Only enable if you use pure server-side integration e.g. not JS Hybrid. |
| 40 | + -- secure: Only enable if your website runs purely on https. |
| 41 | + qit.setOptions({ httpOnly = false, secure = false }) |
| 42 | +
|
| 43 | + qit.handleByIntegrationConfig(customerId, secretKey, integrationConfigJson) |
60 | 44 | } |
61 | | - ``` |
62 | | - |
63 | | -Replace the following two placeholders in the above code `{CUSTOMER_ID}` and `{SECRET_KEY}` with respective values located in GO Queue-it platform. |
64 | | - |
65 | | -NOTE: In this example `rewrite_by_lua_block` directive was added to default location `/` but you must decide what makes sense in your case. |
66 | | - |
67 | | - |
68 | | -### 4) Provide the `integrationconfig.json`... |
69 | | - |
| 45 | +} |
| 46 | +``` |
| 47 | +In this example `rewrite_by_lua_block` have been added to default location `/` but you must decide what makes sense in your case. |
| 48 | +Especially excluding any static content you don't want queue-it protection triggering on. This could be images (.png, .jpg), style (.css) and pages (.html). |
70 | 49 |
|
| 50 | +Please note the comments in the code about providing `integrationconfig.json` ([read more](https://github.com/queueit/KnownUser.V3.Lua#1-providing-the-queue-configuration)) and replacing `CUSTOMER_ID` and `SECRET_KEY` with correct credentials located in GO Queue-it platform. |
71 | 51 |
|
72 | | -## Request body trigger (advanced) |
| 52 | +### Request body trigger (advanced) |
73 | 53 | Nginx handler (incl. Lua SDK) supports triggering on request body content. Example could be a POST call with specific item ID where you want end-users to queue up for. |
74 | 54 | You will need to contact queue-it support if this functionality is needed, so it can be enabled on your GO Queue-it platform account. |
75 | 55 | When enabled you also need to add extra settings to `location` in `conf.d/default.conf`: |
|
0 commit comments