|
| 1 | +# Main configuration directives |
| 2 | +user nginx; |
| 3 | +worker_processes auto; |
| 4 | +error_log /var/log/nginx/error.log warn; |
| 5 | +pid /var/run/nginx.pid; |
| 6 | + |
| 7 | +# Events block |
| 8 | +events { |
| 9 | + worker_connections 1024; |
| 10 | +} |
| 11 | + |
| 12 | +# HTTP block |
| 13 | +http { |
| 14 | + include /etc/nginx/mime.types; |
| 15 | + default_type application/octet-stream; |
| 16 | + |
| 17 | + # Docker's internal DNS resolver |
| 18 | + # When the compose is restarted, the IP addresses of the services might change |
| 19 | + # This is required for resolving the service names to their IP addresses |
| 20 | + resolver 127.0.0.11 ipv6=off; |
| 21 | + |
| 22 | + # SSL Settings |
| 23 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 24 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 25 | + ssl_prefer_server_ciphers on; |
| 26 | + |
| 27 | + # First server block for HTTPS |
| 28 | + server { |
| 29 | + listen 443 ssl; |
| 30 | + server_name helios-staging.aet.cit.tum.de; |
| 31 | + |
| 32 | + ssl_certificate /var/lib/rbg-cert/live/host:f:asevm90.cit.tum.de.fullchain.pem; |
| 33 | + ssl_certificate_key /var/lib/rbg-cert/live/host:f:asevm90.cit.tum.de.privkey.pem; |
| 34 | + |
| 35 | + |
| 36 | + location / { |
| 37 | + # Forward to webapp on port 80 |
| 38 | + proxy_pass http://client:80; |
| 39 | + proxy_http_version 1.1; |
| 40 | + proxy_set_header Upgrade $http_upgrade; |
| 41 | + proxy_set_header Connection 'upgrade'; |
| 42 | + proxy_set_header Host $host; |
| 43 | + proxy_cache_bypass $http_upgrade; |
| 44 | + } |
| 45 | + |
| 46 | + # Proxy API requests |
| 47 | + location /api { |
| 48 | + proxy_pass http://application-server:8080; # Forward to application server |
| 49 | + proxy_http_version 1.1; |
| 50 | + proxy_set_header Upgrade $http_upgrade; |
| 51 | + proxy_set_header Connection 'upgrade'; |
| 52 | + proxy_set_header Host $host; |
| 53 | + proxy_cache_bypass $http_upgrade; |
| 54 | + } |
| 55 | + |
| 56 | + # Proxy Keycloak requests |
| 57 | + location ~* ^/(realms|resources|robots\.txt) { |
| 58 | + proxy_pass http://keycloak:8081; |
| 59 | + proxy_http_version 1.1; |
| 60 | + proxy_set_header Host $host; |
| 61 | + proxy_set_header X-Real-IP $remote_addr; |
| 62 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 63 | + proxy_set_header X-Forwarded-Proto https; |
| 64 | + proxy_set_header X-Forwarded-Port 443; |
| 65 | + proxy_cache_bypass $http_upgrade; |
| 66 | + } |
| 67 | + |
| 68 | + # Keycloak admin console |
| 69 | + location /admin { |
| 70 | + proxy_pass http://keycloak:8081/admin; |
| 71 | + proxy_http_version 1.1; |
| 72 | + proxy_set_header Host $host; |
| 73 | + proxy_set_header X-Real-IP $remote_addr; |
| 74 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 75 | + proxy_set_header X-Forwarded-Proto https; |
| 76 | + proxy_set_header X-Forwarded-Port 443; |
| 77 | + proxy_cache_bypass $http_upgrade; |
| 78 | + } |
| 79 | + |
| 80 | + location /github { |
| 81 | + # Only allow POST requests |
| 82 | + limit_except POST { |
| 83 | + deny all; |
| 84 | + } |
| 85 | + |
| 86 | + # Validate required GitHub headers |
| 87 | + set $valid_headers 1; |
| 88 | + |
| 89 | + if ($http_x_github_event = "") { |
| 90 | + set $valid_headers 0; |
| 91 | + } |
| 92 | + if ($http_x_github_delivery = "") { |
| 93 | + set $valid_headers 0; |
| 94 | + } |
| 95 | + if ($http_x_hub_signature_256 = "") { |
| 96 | + set $valid_headers 0; |
| 97 | + } |
| 98 | + |
| 99 | + # Deny access if headers are invalid |
| 100 | + if ($valid_headers = 0) { |
| 101 | + return 403; |
| 102 | + } |
| 103 | + |
| 104 | + # Forward to the webhook listener service |
| 105 | + proxy_pass http://webhook-listener:4200; # Forward to webhook listener on port 4200 |
| 106 | + proxy_http_version 1.1; |
| 107 | + proxy_set_header Upgrade $http_upgrade; |
| 108 | + proxy_set_header Connection 'upgrade'; |
| 109 | + proxy_set_header Host $host; |
| 110 | + proxy_cache_bypass $http_upgrade; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + # Second server block for HTTP to HTTPS redirection |
| 115 | + server { |
| 116 | + listen 80; |
| 117 | + server_name helios-staging.aet.cit.tum.de; |
| 118 | + |
| 119 | + return 301 https://$host$request_uri; |
| 120 | + } |
| 121 | +} |
0 commit comments