|
| 1 | +# ESP8266 nginx SSL reverse proxy configuration file (tested and working on nginx v1.10.0) |
| 2 | + |
| 3 | +# proxy cache location |
| 4 | +proxy_cache_path /opt/etc/nginx/cache levels=1:2 keys_zone=ESP8266_cache:10m max_size=10g inactive=5m use_temp_path=off; |
| 5 | + |
| 6 | +# webserver proxy |
| 7 | +server { |
| 8 | + |
| 9 | + # general server parameters |
| 10 | + listen 50080; |
| 11 | + server_name myDomain.net; |
| 12 | + access_log /opt/var/log/nginx/myDomain.net.access.log; |
| 13 | + |
| 14 | + # SSL configuration |
| 15 | + ssl on; |
| 16 | + ssl_certificate /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/fullchain.pem; |
| 17 | + ssl_certificate_key /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/privkey.pem; |
| 18 | + ssl_session_cache builtin:1000 shared:SSL:10m; |
| 19 | + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
| 20 | + ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; |
| 21 | + ssl_prefer_server_ciphers on; |
| 22 | + |
| 23 | + location / { |
| 24 | + |
| 25 | + # proxy caching configuration |
| 26 | + proxy_cache ESP8266_cache; |
| 27 | + proxy_cache_revalidate on; |
| 28 | + proxy_cache_min_uses 1; |
| 29 | + proxy_cache_use_stale off; |
| 30 | + proxy_cache_lock on; |
| 31 | + # proxy_cache_bypass $http_cache_control; |
| 32 | + # include the sessionId cookie value as part of the cache key - keeps the cache per user |
| 33 | + # proxy_cache_key $proxy_host$request_uri$cookie_sessionId; |
| 34 | + |
| 35 | + # header pass through configuration |
| 36 | + proxy_set_header Host $host; |
| 37 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 38 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 39 | + |
| 40 | + # ESP8266 custom headers which identify to the device that it's running through an SSL proxy |
| 41 | + proxy_set_header X-SSL On; |
| 42 | + proxy_set_header X-SSL-WebserverPort 50080; |
| 43 | + proxy_set_header X-SSL-WebsocketPort 50081; |
| 44 | + |
| 45 | + # extra debug headers |
| 46 | + add_header X-Proxy-Cache $upstream_cache_status; |
| 47 | + add_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 48 | + |
| 49 | + # actual proxying configuration |
| 50 | + proxy_ssl_session_reuse on; |
| 51 | + # target the IP address of the device with proxy_pass |
| 52 | + proxy_pass http://192.168.0.20; |
| 53 | + proxy_read_timeout 90; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | +# websocket proxy |
| 58 | +server { |
| 59 | + |
| 60 | + # general server parameters |
| 61 | + listen 50081; |
| 62 | + server_name myDomain.net; |
| 63 | + access_log /opt/var/log/nginx/myDomain.net.wss.access.log; |
| 64 | + |
| 65 | + # SSL configuration |
| 66 | + ssl on; |
| 67 | + ssl_certificate /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/fullchain.pem; |
| 68 | + ssl_certificate_key /usr/builtin/etc/certificate/lets-encrypt/myDomain.net/privkey.pem; |
| 69 | + ssl_session_cache builtin:1000 shared:SSL:10m; |
| 70 | + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
| 71 | + ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; |
| 72 | + ssl_prefer_server_ciphers on; |
| 73 | + |
| 74 | + location / { |
| 75 | + |
| 76 | + # websocket upgrade tunnel configuration |
| 77 | + proxy_pass http://192.168.0.20:81; |
| 78 | + proxy_http_version 1.1; |
| 79 | + proxy_set_header Upgrade $http_upgrade; |
| 80 | + proxy_set_header Connection "Upgrade"; |
| 81 | + proxy_read_timeout 86400; |
| 82 | + } |
| 83 | + } |
0 commit comments