|
| 1 | +# devproxy |
| 2 | + |
| 3 | +## What is devproxy? |
| 4 | + |
| 5 | +devproxy is intended to be an easily configurable forward HTTP proxy for web application development. |
| 6 | + |
| 7 | +It has the following feature: |
| 8 | + |
| 9 | +* URL rewriting |
| 10 | + |
| 11 | + If the upstream HTTP server listens on `127.0.0.1:3000` and you want to get your browser to access to it by a request to `http://example.com`, the configuration should look as follows: |
| 12 | + |
| 13 | + ``` |
| 14 | +hosts: |
| 15 | + http://example.com: |
| 16 | + - ^(/*)$: http://127.0.0.1:3000$1 |
| 17 | + ``` |
| 18 | + |
| 19 | +* Transparent TLS wrapping (simulation of an SSL/TLS-enabled environment) |
| 20 | + |
| 21 | + You can also make it possible to access to the upstream by hitting `https://example.com/` by adding the configuration like the following: |
| 22 | + |
| 23 | + ``` |
| 24 | +hosts: |
| 25 | + http://example.com: |
| 26 | + - ^(/*)$: http://127.0.0.1:3000$1 |
| 27 | + https://example.com: |
| 28 | + - ^(/*)$: http://127.0.0.1:3000$1 |
| 29 | + ``` |
| 30 | + |
| 31 | + It is however necessary to set up the private PKI for issuing bogus server certificates and let your browser trust the PKI's root CA certificate. **DO IT YOUR OWN RISK.** |
| 32 | + |
| 33 | + The CA for issuing bogus server certificates is configured as follows: |
| 34 | + |
| 35 | + ``` |
| 36 | +tls: |
| 37 | + ca: |
| 38 | + cert: testca.rsa.crt.pem |
| 39 | + key: testca.rsa.key.pem |
| 40 | +hosts: |
| 41 | + ... |
| 42 | +``` |
| 43 | + |
| 44 | +* Request header modification |
| 45 | + |
| 46 | + You can add / remove arbitrary request HTTP headers for the request being rewritten: |
| 47 | + |
| 48 | + ``` |
| 49 | +hosts: |
| 50 | + http://example.com: |
| 51 | + - ^(/*)$: http://127.0.0.1:3000$1 |
| 52 | + headers: |
| 53 | + X-Forwarded-Proto: https |
| 54 | + Removed-Header: null |
| 55 | +``` |
| 56 | + |
| 57 | +* Testing FastCGI-enabled upstream |
| 58 | + |
| 59 | + You can forward the request to a FastCGI-enabled upstream: |
| 60 | + |
| 61 | + ``` |
| 62 | +hosts: |
| 63 | + http://example.com: |
| 64 | + - ^(((?:/.*)*/[^/]+\.php)(/.*|$)): fastcgi://localhost$1 |
| 65 | + headers: |
| 66 | + X-Cgi-Script-Filename: /var/www/document/root$2 |
| 67 | + X-Cgi-Script-Name: $2 |
| 68 | + X-Cgi-Path-Info: $3 |
| 69 | +``` |
| 70 | + |
| 71 | + |
| 72 | +## Installation |
| 73 | + |
| 74 | +``` |
| 75 | +go get github.com/moriyoshi/devproxy |
| 76 | +``` |
| 77 | + |
| 78 | +## Using devproxy |
| 79 | + |
| 80 | +``` |
| 81 | +$GOPATH/bin/devproxy -l listen_addr configuration_file |
| 82 | +# ex: $GOPATH/bin/devproxy -l 127.0.0.1:8080 config.yml |
| 83 | +``` |
| 84 | + |
| 85 | +And Adjust your browser's proxy settings to what is exactly given to `-l` option. |
| 86 | + |
| 87 | +## Setting up the private PKI |
| 88 | + |
| 89 | +``` |
| 90 | +openssl genrsa 2048 > testca.rsa.key.pem |
| 91 | +openssl req -new -key testca.rsa.key.pem -out testca.rsa.csr.pem |
| 92 | +openssl x509 -req -in testca.rsa.csr.pem -signkey testca.rsa.key.pem -days 3650 -extfile x509.ini -extensions CA -out testca.rsa.crt.pem |
| 93 | +``` |
| 94 | + |
| 95 | +x509.ini: |
| 96 | +``` |
| 97 | +[CA] |
| 98 | +basicConstraints=critical,CA:TRUE,pathlen:1 |
| 99 | +keyUsage=digitalSignature,keyCertSign,cRLSign |
| 100 | +``` |
| 101 | + |
| 102 | +## Configuration file example |
| 103 | + |
| 104 | +``` |
| 105 | +tls: |
| 106 | + client: |
| 107 | + verify: true |
| 108 | + ca: |
| 109 | + cert: testca.rsa.crt.pem |
| 110 | + key: testca.rsa.key.pem |
| 111 | +
|
| 112 | +hosts: |
| 113 | + http://api.example.com: |
| 114 | + - ^(/v1/.*)$: http://localhost:8000$1 |
| 115 | + - ^(/v2/.*)$: http://localhost:8001$1 |
| 116 | + http://example.com: |
| 117 | + - ^(/asset.*)$: http://localhost:8002$1 |
| 118 | + - ^(/.*)$: http://localhost:8003$1 |
| 119 | +``` |
0 commit comments