我想代理将来自一系列端口的所有请求传递到单个端口。我能够代理将单个端口传递给另一个端口,如下所示:
server {
listen 3333;
server_name test.in *.test.in;
location / {
proxy_pass http://10.1.1.2:5479/;
include /etc/nginx/proxy_params;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试 test.in:3333 时,它会重定向到 10.1.1.2:5479。
以同样的方式,我需要代理传递这些:
test.in 4440 to 10.1.1.2:5479
test.in 4441 to 10.1.1.2:5479
test.in 4442 to 10.1.1.2:5479
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我已经在 Ubuntu 22.04 服务器上设置了 nginx 反向代理,并且已成功从 Lets Encrypt 获取 ssl 证书。两个密钥存储在这里:
/etc/letsencrypt/live/test.ddns.net/fullchain.pem;
/etc/letsencrypt/live/test.ddns.net/privkey.pem
Run Code Online (Sandbox Code Playgroud)
在我的默认 nginx 配置中,我有两个路径helloworld和portainer。两条路径都重定向到 docker 容器。
server {
listen 80;
listen [::]:80;
server_name test.ddns.net;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name test.ddns.net;
ssl_certificate /etc/letsencrypt/live/test.ddns.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/test.ddns.net/privkey.pem;
location /helloworld {
proxy_pass http://localhost:32768;
}
location /portainer {
proxy_pass http://localhost:9000;
}
Run Code Online (Sandbox Code Playgroud)
helloworld 路径按预期工作,并使用 https 协议加载 html 页面(因此我的 ngnix 配置是正确的)。但portainer路径不是。我尝试了端口 9000、端口 8000、端口 9443。但都不起作用。我收到 404 错误,或者通过 http 发送的请求,而预期是 https,或者其他错误。有没有人有相同的设置并且能够帮助我?
谢谢。