swoole 建立httpserver 服务[通俗易懂]

swoole 建立httpserver 服务

大家好,又见面了,我是全栈君。

1.上代码:http_server.php文件

<?php
/**
 *User: lxw
 *Date: 2020-01-16
 */

/*$http = new Swoole\Http\Server("127.0.0.1", 9501);

$http->on('request', function ($request, $response) {
    var_dump($request->get, $request->post);
    $response->header("Content-Type", "text/html; charset=utf-8");
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});

$http->start();*/

$http = new swoole_http_server('0.0.0.0', 8811);

$http->on('request', function ($request, $response) {
//    print_r($request->get);
    $response->end("ss".json_encode($request->get));
//    $response->end("<h1> http server</h1>>");
    //end :发送html响应体,并结束请求处理,  end操作后将向客户端浏览器发送html内容
    //end 只能调用一次,如果需要向客户端发送多次数据,请使用write
});
//开启服务
$http->start();

2.服务端:启动服务

swoole 建立httpserver 服务[通俗易懂]

3.客户端:浏览器,谷歌浏览器带上子域名前缀www

http://www.httpserver.com:8811/?m=222

swoole 建立httpserver 服务[通俗易懂]

4.补充httpserver.com 在NGINX中配置

server
    {
        listen 8811;
        #listen [::]:80 default_server ipv6only=on;
        server_name httpserver.com  www.httpserver.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/default/newproject/swoolechat/swoole-src/examples/server;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location / {
            if (!-e $request_filename){
                rewrite ^/(.*)$ /index.php?s=/$1 last;
            }
        }
                location ~ /\.
        {
          deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

5.如果出现拒绝访问:考虑下防火墙

如果要修改防火墙配置,如增加防火墙端口3306

vi /etc/sysconfig/iptables 

增加规则

-A INPUT -p tcp -m state --state NEW -m tcp --dport 8811 -j ACCEPT

或,参数顺序前后没区别

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8811 -j ACCEPT

swoole 建立httpserver 服务[通俗易懂]

重新启动iptables ,使其生效

swoole 建立httpserver 服务[通俗易懂]

======================================================

额外补充:

nignx 与swoole hhtp-server 不能同时开启,两者只能开启其一;两者不能共存.

swoole 建立httpserver 服务[通俗易懂]swoole 建立httpserver 服务[通俗易懂]

两者切换,ctrl+c 取消swoole-http-server 服务器,service nginx restart 重启NGINX 服务器;

swoole 建立httpserver 服务[通俗易懂]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/111941.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • HTML5触摸事件(touchstart、touchmove和touchend)

    HTML5触摸事件(touchstart、touchmove和touchend)HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享。今天为大家介绍的事件主要是触摸事件:touchstart、touchmove和touchend。  一开始触摸事件touchstart、touchmove和touchend是iOs版Safari浏览器为了向开发人员

    2022年6月19日
    32
  • pychar激活码3月最新在线激活

    pychar激活码3月最新在线激活,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月14日
    48
  • 使用Keras实现 基于注意力机制(Attention)的 LSTM 时间序列预测

    时隔半年多,毕设男孩终于重操旧业,回到了LSTM进行时间序列预测和异常检测的路上。如果有阅读过我之前的博客,可以发现使用LSTM作单类的时间序列异常检测也是基于对于时间序列的预测进行登堂入室LSTM:使用LSTM进行简单的时间序列异常检测本次我们要进行的是使用注意力机制+LSTM进行时间序列预测,项目地址为KerasAttentionMechanism首先我们把它git…

    2022年4月6日
    573
  • pycharm django开发_django项目实例精解

    pycharm django开发_django项目实例精解1.首先按往常“NewProject”创建新项目2.在下方Terminal终端输入django-adminstartprojectroomroom是我的项目名称3.新建app目录pythonmanage.pystartappappapp是我起的名称,可以换成其他的4.运行在终端cd进入manage.py路径后输入命令pythonmanage.pyrunserver8000点击此处链接就可以了这是运行成功界面。参考自https://www.jianshu.com

    2022年8月28日
    0
  • MySQL proxy读写分离

    MySQL proxy读写分离

    2021年9月9日
    49
  • 使用 Converter Standalone进行P2V操作指导「建议收藏」

    使用 Converter Standalone进行P2V操作指导「建议收藏」介绍VMwarevCenterConverterStandalone是一款免费程序,可以安装在运行Windows的物理计算机上。ConverterStandalone会将硬盘驱动器上的数据复制到虚拟磁盘文件(.vmdk)中,此文件随后可在其他VMware产品中使用。该过程不会影响您的计算机,在使用Converter之后您可以继续使用计算机。VMwarevCenterConverter可以在多种硬件上运行,并支持最常用的MicrosoftWindows操作系统版本

    2022年7月26日
    17

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号