webman:用nginx做代理(v1.5.7)
一,官方文档地址:
https://www.workerman.net/doc/webman/others/nginx-proxy.html
二,配置nginx
添加一个host
upstream webman {
server 127.0.0.1:8787;
keepalive 10240;
}
server {
server_name imgadm.liuhongdi.com;
listen 8808;
access_log off;
root /data/webman/imageadmin/public;
location ^~ / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
if (!-f $request_filename){
proxy_pass http://webman;
}
}
}
三,测试效果:
默认端口:
nginx代理端口:
说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/09/19/webman-yong-nginx-zuo-dai-li-v1-5-7/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
四,webman从nginx后面获取用户的真实ip
此两个方法有效:
$ip = $request->header('X-Real-IP');
$ip = $request->getRealIp();
echo "ip:".$ip."<br/>";
使用$request->getRemoteIp() 只能得到127.0.0.1
五,查看nginx版本 :
liuhongdi@lhdpc:/data/webman/imageadmin$ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)