%20%E6%9D%A5%E8%87%AA%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E7%A9%BA%E5%9B%9E%E5%A4%8D%E2%80%9D.png)
我正在尝试设置反向代理以将 tcp 从 subdomain.example.com 重定向到localhost:3000
使用 Nginx 的ssl_preread_server_name
模块。
主机test.localhost
是为了测试目的而定义的/etc/hosts/
。
我的/etc/nginx/nginx.conf
:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
stream {
map $ssl_preread_server_name $name {
test.localhost test;
}
upstream test {
server localhost:3000;
}
server {
listen 2600;
proxy_pass $name;
#proxy_protocol on;
ssl_preread on;
}
}
当我直接尝试网络应用程序时curl
:
$ curl localhost:3000
Hello World!
但是当我尝试代理时:
$ curl -vvv test.localhost:2600
* Trying 127.0.0.1:2600...
* Connected to test.localhost (127.0.0.1) port 2600 (#0)
> GET / HTTP/1.1
> Host: test.localhost:2600
> User-Agent: curl/7.74.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host test.localhost left intact
curl: (52) Empty reply from server
将其更改为proxy_pass test;
可以,但我希望多个子域将 TCP 流式传输到不同的本地端口。
答案1
重点是SSL。
也许你应该尝试
curl https://test.localhost:2600