{"id":16772626,"url":"https://github.com/jonlabelle/docker-nginx-regex-tester","last_synced_at":"2025-03-16T16:33:39.593Z","repository":{"id":148059617,"uuid":"326468954","full_name":"jonlabelle/docker-nginx-regex-tester","owner":"jonlabelle","description":"Provides a mechanism for testing regular expressions directly within an NGINX configuration.","archived":false,"fork":false,"pushed_at":"2021-01-25T23:56:34.000Z","size":105,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T03:29:24.307Z","etag":null,"topics":["docker","docker-image","nginx","php","regex"],"latest_commit_sha":null,"homepage":"https://github.com/jonlabelle/docker-nginx-regex-tester","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonlabelle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-03T18:00:46.000Z","updated_at":"2024-07-09T14:10:03.000Z","dependencies_parsed_at":"2023-05-28T08:00:15.625Z","dependency_job_id":null,"html_url":"https://github.com/jonlabelle/docker-nginx-regex-tester","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonlabelle%2Fdocker-nginx-regex-tester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonlabelle%2Fdocker-nginx-regex-tester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonlabelle%2Fdocker-nginx-regex-tester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonlabelle%2Fdocker-nginx-regex-tester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonlabelle","download_url":"https://codeload.github.com/jonlabelle/docker-nginx-regex-tester/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243896620,"owners_count":20365405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-image","nginx","php","regex"],"created_at":"2024-10-13T06:43:26.633Z","updated_at":"2025-03-16T16:33:39.574Z","avatar_url":"https://github.com/jonlabelle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker NGINX Regular Expression Tester\n\n\u003e Based on \u003chttps://github.com/nginxinc/NGINX-Demos/tree/master/nginx-regex-tester\u003e and article [A Regular Expression Tester for NGINX and NGINX Plus](https://www.nginx.com/blog/regular-expression-tester-nginx/).\n\n## Overview\n\nProvides a mechanism for testing regular expressions directly within an NGINX\nconfiguration.\n\nNGINX Unit is used to serve a PHP page that creates an NGINX configuration to\nuse to test the regular expression.\n\nNGINX and Unit are run together in the same container.\n\n### Components\n\n|            Component            |                                         Description                                         |\n|---------------------------------|---------------------------------------------------------------------------------------------|\n| `docker-compose.yml`            | The configuration file for Docker Compose to build the image and create the container.      |\n| `/regextester/Dockerfile`       | Creates a Docker image, _regextester_ based on the NGINX F/OSS image and adding NGINX Unit. |\n| `/regextester/regextester.conf` | The base NGINX configuration file for this application, proxying requests to NGINX Unit.    |\n\n```nginx\nupstream regextester {\n    server 127.0.0.1:8000;\n}\n\nserver {\n    listen 80;\n\n    location / { # Included so start.sh can see that NGINX is running\n        root /usr/share/nginx/html;\n    }\n\n    location ~ \\.php$ {\n        proxy_pass http://regextester;\n    }\n}\n```\n\n**/regextester/regextester.php:** A page where the user chooses whether the\nregular expression is for a location or map and then enteres the required\nvalues. The necessary NGINX configuration is generated and NGINX is reloaded.\nThe regex is then tested and the results displayed.\n\nThe format of the NGINX configuration file to be generated depends on whether\nthe regex is to be used in a location or a map.\n\nFor a location it will be of the form:\n\n```nginx\nserver {\n    listen 9000;\n\n    location / {\n        return 200 \"Match not found\\n\";\n    }\n\n    location ~ \u003cregex\u003e {\n        return 200 \"Match found [Capture Group(s) 1: $i 2: $i ...]\\n\";\n    }\n}\n```\n\nFor example, if the regex is `(.*)/(.*).php$` and it is case insensitive the\ngenerated configuration file will be:\n\n```nginx\nserver {\n    listen 9000;\n\n    location / {\n        return 200 \"Match not found\\n\";\n    }\n\n    location ~* (.*)/(.*).php$ {\n        return 200 \"Match found. Capture Groups 1: $i 2: $2\\n]\";\n    }\n}\n```\n\nHere is a screen shot of the PHP page with the results for the URI _/myapp/hello.php_:\n\n![screen shot of the PHP page with the results for the URI](screen_shot_loc.png)\n\nFor a map, the NGINX configuration files will be of the form:\n\n```nginx\n map $variable $value {\n     ~[*]\u003cregex\u003e \"Match found: \u003cvalue to set\u003e;\n     default \"No match found:\";\n }\n\n server {\n     listen 9000;\n\n     set $variable \"\u003cvalue to set\u003e\";\n\n     location / {\n        return 200 \"$value\\n\";\n    }\n }\n```\n\nFor example, if the regex is `\\.php$`, the value to test is _hello.php_, the\nvalue to set if a match is found is _php_ and it is case sensitive, the\ngenerated configuration file will be:\n\n```nginx\n map $variable $value {\n     ~\\.php$ \"Match found. Value set to: php\";\n     default \"No match found:\";\n }\n\n server {\n     listen 9000;\n\n     set $variable \"hello.php\";\n\n     location / {\n        return 200 \"$value\\n\";\n    }\n }\n```\n\nIf the regex is `.*\\.(?\u003csfx\u003e.*)$`, the value to test is _hello.php_, the value\nto set if a match is found is _$sfx_ and it is case insensitive, the generated\nconfiguration file will be:\n\n```nginx\n map $variable $value {\n     ~*.*\\.(?\u003csfx\u003e.*)$ \"Match found. Value set to: $sfx\";\n     default \"No match found:\";\n }\n\n server {\n     listen 9000;\n\n     set $variable \"hello.php\";\n\n     location / {\n        return 200 \"$value\\n\";\n    }\n }\n```\n\nHere is a screen shot of the PHP page with the results:\n\n![Screen shot of the PHP page with the results](screen_shot_map.png)\n\n- `/regextester/start.sh` - The start script specified in the Dockerfile to start NGINX and Unit and configure Unit.\n- `/regextester/unitphp.config` - The Unit configuration.\n\n## Usage\n\n1. Run `docker-compose up -d` to build the image and start a container.\n2. Open your web browser to \u003chttp://127.0.0.1/regextester.php\u003e.\n3. Enter required information then press the _Test_ button.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonlabelle%2Fdocker-nginx-regex-tester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonlabelle%2Fdocker-nginx-regex-tester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonlabelle%2Fdocker-nginx-regex-tester/lists"}