Advertisement
Kenya-West

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

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