Initial Commit

This commit is contained in:
2018-05-11 21:25:11 +02:00
commit b2125dd4be
5 changed files with 73 additions and 0 deletions

12
Dockerfile Normal file
View File

@ -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;'

19
LICENSE Normal file
View File

@ -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.

13
README.md Normal file
View File

@ -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
```

26
default.template Normal file
View File

@ -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;
}
}

3
script.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "Hello there c:<"