19人参与 • 2025-07-20 • Linux
yum -y install make zlib zlib-devel gcc-c++
pcre download | sourceforge.net
tar -zxvf pcre-8.38.tar.gz cd pcre-8.38 ./configure make make install
安装完可以 pcre-config --version 查看pcre已经安装好了,版本为8.38
tar -zxvf nginx-1.21.5.tar.gz cd nginx-1.21.5 ./configure --prefix=/usr/local/nginx --with-stream make make install
cd /usr/local/nginx/conf vim nginx.conf
如图,在events和http块之间插入 代码段stream,用来转发socket
stream{ upstream abcdef{ server 127.0.0.1:9988; } server{ listen 9999; proxy_pass abcdef; } }
http服务转发是http内部的server内的location
cd /usr/local/nginx/sbin ./nginx ps -ef|grep nginx
这样就可以通过9999端口访问原来发布在9988端口的socket服务
通过801端口访问原来发布在1557端口的http服务
[root@localhost ~]# curl http://192.168.137.141:801/multiply?a=3\&b=4 {"res": "12"}[root@localhost ~]# curl http://192.168.137.141:801/add?a=3\&b=4 {"res": "7"}[root@localhost ~]# curl http://192.168.137.141:1557/multiply?a=3\&b=4 {"res": "12"}[root@localhost ~]# curl http://192.168.137.141:1557/add?a=3\&b=4 {"res": "7"}[root@localhost ~]#
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论