栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Swoole httpserver浏览器外部无法访问

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Swoole httpserver浏览器外部无法访问

HttpServer 背景

swoole是异步、协程并行的通讯引擎,所以B/S架构网络引擎一定是会用到的。所以浏览器上访问自然少不了。

解决方案:

总结两点:

1、关闭防火墙
2、安全组放行对应端口

源码如下

on("start", function ($server) { // 启动事件
  echo "Swoole http server is started at http://8.134.49.245n";
});

// http 请求事件
$http->on("request", function ($request, $response) {
  $response->header("Content-Type", "text/plain");
  $response->end("Hello World,Swoole study n");
});

echo "start 前n";

// 启动swoole的服务
$http->start();

echo "start end";

操作过程 1、启动服务
[root@iZ7xv0j6qg6j84hey84c6tZ 01]# php test.php 
start 前
Swoole http server is started at http://192.168.169.100:9501

2、访问服务

本地ip正常响应;

curl或者浏览器访问ip:端口均没有响应

[root@iZ7xv0j6qg6j84hey84c6tZ ~]# curl http://127.0.0.1:9501
Hello World ,Swoole study 

[root@iZ7xv0j6qg6j84hey84c6tZ ~]# curl http://8.134.49.245:9501
^C
3、查看防火墙状态并关闭,也是无法响应

注:centos7.9下

[root@iZ7xv0j6qg6j84hey84c6tZ ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
  Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
  Active: active (running) since Fri 2022-06-10 23:10:02 CST; 15h ago
    Docs: man:firewalld(1)
Main PID: 17049 (firewalld)
  CGroup: /system.slice/firewalld.service
          └─17049 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Jun 10 23:10:02 iZ7xv0j6qg6j84hey84c6tZ systemd[1]: Starting firewalld - dynamic firewall daemon...
Jun 10 23:10:02 iZ7xv0j6qg6j84hey84c6tZ systemd[1]: Started firewalld - dynamic firewall daemon.
Jun 10 23:10:02 iZ7xv0j6qg6j84hey84c6tZ firewalld[17049]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration o...it now.
Jun 11 14:52:38 iZ7xv0j6qg6j84hey84c6tZ firewalld[17049]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration o...it now.
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ7xv0j6qg6j84hey84c6tZ ~]# systemctl stop firewalld.service
[root@iZ7xv0j6qg6j84hey84c6tZ ~]# curl http://8.134.49.245:9501
^C
[root@iZ7xv0j6qg6j84hey84c6tZ ~]# curl http://8.134.49.245:9501
^C

4、登录云服务 -> 安全组 -> 9501端口放行,正常响应了。
[root@iZ7xv0j6qg6j84hey84c6tZ ~]# curl http://8.134.49.245:9501
Hello World ,Swoole study 

重要提醒下:
1 、访问swoole httpserve,一定是 ip:端口访问,而不是访问访问文件路径。对于新手特别注意

2、进程查看:ps -aux 文件名.php;而不是 ps -aux swoole

3、查看端口对应进程id :netstat -anp | grep 9501
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/974503.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号