Advertisement
Kenya-West

A snippet for https://t.me/nginx_ru #1

Oct 13th, 2024
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 1.40 KB | Source Code | 0 0
  1. events {}
  2.  
  3. error_log /var/log/nginx/error.log debug;
  4.  
  5. http {
  6.     map $http_x_proxy_port $proxy_port {
  7.         default 80;  # Default port if X-PROXY-PORT header is not set
  8.     }
  9.  
  10.     log_format custom_debug 'Host: $host, Container: $container, Port: $proxy_port, Path: $uri, X-PROXY-PORT: $http_x_proxy_port';
  11.     access_log /var/log/nginx/access.log custom_debug;
  12.  
  13.     server {
  14.         listen 80;
  15.         http2 on;
  16.         server_name proxy;
  17.  
  18.         location / {
  19.             root /usr/share/nginx/html;
  20.             index index.html;
  21.  
  22.             proxy_set_header Host $host;
  23.             proxy_set_header X-Real-IP $proxy_protocol_addr;
  24.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  25.             proxy_set_header X-Forwarded-Proto $scheme;
  26.         }
  27.  
  28.         location ~ ^/proxy/([^/]+)(/.*)?$ {
  29.             # Extract container name from the URL
  30.             set $container $1;
  31.             set $rest_of_path $2;
  32.  
  33.  
  34.             # Proxy the request to the respective container and port
  35.             proxy_pass http://$container:$proxy_port$rest_of_path;
  36.             proxy_set_header Host $host;
  37.             proxy_set_header X-Real-IP $remote_addr;
  38.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  39.             proxy_set_header X-Forwarded-Proto $scheme;
  40.  
  41.             # Additional proxy settings
  42.             proxy_redirect off;
  43.         }
  44.     }
  45. }
  46.  
Tags: nginx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement