Nginx 域名转发到指定端口设置教程
- 在 Nginx 配置文件中添加一个 server 块,指定要转发的域名和监听的端口号,例如:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
-
在 location 中使用
proxy_pass指令将请求转发到指定的端口,这里使用的是本地的 8080 端口。 -
使用
proxy_set_header指令设置请求头,其中 Host 头用于指定访问的域名,X-Real-IP 头用于传递客户端的真实 IP 地址。 -
保存配置文件并重启 Nginx 服务生效。
原文地址: https://www.cveoy.top/t/topic/lRtB 著作权归作者所有。请勿转载和采集!