Очень простая идея:
Я хочу перенаправить на серверы: порт по следующей схеме:
requesting domain.com/9000/blabla will proxy pass to 127.0.0.1:9000
requesting domain.com/9002/asdasd will proxy pass to 127.0.0.1:9002
У меня есть одно правило для одного прохода:
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:9001;
}
Но как получить порт из имени маршрута в качестве переменной для аргумента proxy_pass
?
Также, пожалуйста, позаботьтесь, мне нужно, чтобы запрошенный URL-адрес для пропущенных прокси должен быть все после номера порта из исходный маршрут, поэтому для:
domain.com/9000/blabla
Запрашиваемый URL должен быть не /9000/blabla
, а /blabla
.
Я надеюсь, что все это возможно с nginx. Большое спасибо!
ВЫПУСК CURL:
curl -v "https://dd.aa.com/9001/dada"
* Trying XXXXX.XXX.XXX.XXX...
* TCP_NODELAY set
* Connected to dd.aa.com (XXXXX.XXX.XXX.XXX) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Unknown (8):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Client hello (1):
* TLSv1.3 (OUT), TLS Unknown, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=dd.aa.com
* start date: Apr 2 08:20:16 2020 GMT
* expire date: Jul 1 08:20:16 2020 GMT
* subjectAltName: host "dd.aa.com" matched cert's "dd.aa.com"
* issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* Using Stream ID: 1 (easy handle 0x55b7e45d5580)
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
> GET /9001/dada HTTP/2
> Host: dd.aa.com
> User-Agent: curl/7.58.0
> Accept: */*
>
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
< HTTP/2 308
< server: nginx
< date: Thu, 02 Apr 2020 11:42:17 GMT
< content-type: text/html; charset=utf-8
< content-length: 303
< location: http://dd.aa.com/dada/
< access-control-allow-origin: *
< x-powered-by: PleskLin
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
* Connection #0 to host dd.aa.com left intact
<p>You should be redirected automatically to target URL: <a href="http://dd.aa.com/dada/">http://dd.aa.com/dada/</a>. If not click the link.