commit b2125dd4be5c3cb4d369d12eef5d49d192938be3 Author: Joakim Hulthe Date: Fri May 11 21:25:11 2018 +0200 Initial Commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..19044b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM nginx:alpine + +EXPOSE 80 + +ENV PROXY_PASS_HOST=http://example.com + +COPY default.template /etc/nginx/conf.d/default.template + +COPY script.sh /usr/share/nginx/script.sh + +CMD envsubst '$PROXY_PASS_HOST' < etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && \ + nginx -g 'daemon off;' diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1a647ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018 Joakim Hulthe + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6c251be --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +curl\_sh +======== +_A User-Agent based proxy_ + +This nginx configuration will return `script.sh` if the user-agent matches "**curl**". +In any other case it will act as a reverse-proxy to `PROXY_PASS_HOST`. + +### Usage + +```sh +$ docker build . -t curl_sh +$ docker run -e PROXY_PASS_HOST=http://my_host:1234 --rm curl_sh +``` diff --git a/default.template b/default.template new file mode 100644 index 0000000..226a1db --- /dev/null +++ b/default.template @@ -0,0 +1,26 @@ +server { + listen 80; + server_name _; + + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + error_page 418 = @pass; + recursive_error_pages on; + if ( $http_user_agent !~ 'curl' ) { + return 418; + } + + root /usr/share/nginx; + try_files /script.sh =404; + } + + location @pass { + proxy_pass $PROXY_PASS_HOST; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_redirect default; + } +} + diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..c507c71 --- /dev/null +++ b/script.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "Hello there c:<"