nginx配置中proxy_pass http://$host:8082; 端口可以配置多个吗?

  • 作者: 凯哥Java(公众号:凯哥Java)
  • frp
  • 时间:2023-06-14 10:14
  • 3087人已阅读
简介 在使用frp内网穿透的时候,有时候,我们需要多个端口。那么就需要在nginx中配置多个端口。现在配置一个端口使用的是proxy_passhttp://$host:8082;。如下图:那么想要配置多个端口怎么配置?在nginx的proxy_pass中配置多个端口是不可能的,因为proxy_pass只能指向一个具体的后端服务器。如果需要配置多个端口,则需要在nginx中配置多个upstream模块,每

🔔🔔好消息!好消息!🔔🔔

 如果您需要注册ChatGPT,想要升级ChatGPT4。凯哥可以代注册ChatGPT账号代升级ChatGPT4

有需要的朋友👉:微信号 kaigejava2022

在使用frp内网穿透的时候,有时候,我们需要多个端口。那么就需要在nginx中配置多个端口。

现在配置一个端口使用的是

proxy_pass http://$host:8082;。如下图:

bb807892343fd9cc4d6c09e6aed68f84.png

那么想要配置多个端口怎么配置?

在nginx的proxy_pass中配置多个端口是不可能的,因为proxy_pass只能指向一个具体的后端服务器。如果需要配置多个端口,则需要在nginx中配置多个upstream模块,每个模块指向一个具体的后端服务器和端口。例如:

upstream backend1 {
    server backend1.example.com:8080;
}

upstream backend2 {
    server backend2.example.com:8081;
}

server {
    listen 80;
    server_name example.com;
    location / {
        proxy_pass http://backend1;
        proxy_set_header Host $host;
    }
}

server {
    listen 80;
    server_name example2.com;
    location / {
        proxy_pass http://backend2;
        proxy_set_header Host $host;
    }
}


TopTop