nginx端口转发怎么配置

要配置 nginx 进行端口转发,需要编辑 nginx 的配置文件。

打开 nginx 配置文件。一般位置是 /etc/nginx/nginx.conf/etc/nginx/conf.d/default.conf

http 部分添加以下内容:

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;
    }
}

保存并退出配置文件。

重新启动 nginx 服务。

现在,当访问 http://example.com 时,nginx 会将请求转发到 http://localhost:8080。确保后端服务在目标地址上运行,并且防火墙允许进行端口转发。

阅读剩余
THE END