-
安装Nginx:
- 在 Ubuntu 系统上运行:
sudo apt update sudo apt install nginx
- 启动并启用 Nginx:
sudo systemctl start nginx sudo systemctl enable nginx
- 在 Ubuntu 系统上运行:
-
配置Nginx作为反向代理:
-
打开默认配置文件:
sudo nano /etc/nginx/sites-available/default
-
修改
server块,设置正确的域名和端口:server_name 192.168.1.100:808; listen 808; server_root /var/www/html; location / { proxy_pass http://target.com:80; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } -
保存并退出编辑器。
-
-
重新加载Nginx配置:
- 运行:
sudo nginx -t
- 如果没有错误,启动 Nginx:
sudo systemctl restart nginx
- 运行:
-
配置客户端代理:
- 在浏览器或其他应用程序中,设置代理服务器:
- 浏览器:进入设置,选择“高级网络设置”,在代理服务器部分输入服务器IP和端口(如192.168.1.100:808)。
- 命令行:在终端中设置环境变量:
export http Proxy=192.168.1.100:808 export https Proxy=192.168.1.100:808
- 在浏览器或其他应用程序中,设置代理服务器:
-
验证配置:
- 使用 curl 命令测试:
curl -I http://localhost:808
- 检查返回码和内容是否正确。
- 使用 curl 命令测试:
-
检查防火墙设置:
- 打开808端口:
sudo ufw allow out 808
- 查看防火墙状态:
sudo ufw status
- 打开808端口:
-
管理权限和安全:
- 确保 Nginx 用户有足够权限运行。
- 如果需要 SSL,配置证书,例如使用 Let's Encrypt 的证书。
通过以上步骤,您可以成功配置代理服务器,实现请求的转发和中转功能。









