docker nginx php 不能访问_Api监控统计Swoole Statistic在Docker中的部署

4ea539ff1a8b37f692787ceee2873252.png

swoole statistic是一个可以监控API访问频率、耗时、成功率的系统。

传送门 —> https://github.com/toxmc/statistics

准备:

Swoole php容器 (使用的是官方的源)
Nginx容器

在宿主机项目目录中运行以下命令 拉取swoole statistic项目 (宿主机该目录已经挂载到swoole php容器中 属于基础入门知识,查看博客docker栏目或者百度~)

git clone git@github.com:toxmc/statistics.git statistics

进入该目录中

cd statistics

启动运行

php web.php
php worker.php

接着需要配置nginx虚拟主机 绑定域名 swoole statistic项目中已经带有conf文件 (Readme.md也有简易步骤说明)

nginx.conf中加上以下内容

upstream swoole_statistics  {
    //  这是项目原来文件的写法  不能这样子写 server 127.0.0.1:6666; #swoole_http_server 
    server 172.17.0.2:6666; // 要这样子写   172.17.0.2是你的swoole php容器的容器ip  关于如何查看该ip可以百度 docker 查看容器ip
}
## Start tongji.val.xyz ##
server {
    listen 80;
    server_name statistics.xxx.com; // 这里是你的域名 
    root   /Users/xmc/PhpstormProjects/statistics/Web;
    index  index.html index.htm index.php;
    ## send request back to swoole_http_server ##
    location / {
        #proxy_pass http://127.0.0.1:6666;
        proxy_pass http://swoole_statistics;
        #Proxy Settings
        proxy_redirect     off;
        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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }
   location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|css|ico)$
   {
        access_log off;
        expires 0d;
   }
}

重启nginx容器

docker restart nginx(你nginx容器的名字)

访问刚刚绑定的域名 即可看到web后台 登录,配置数据源 填入0.0.0.0

接着把 swoole statistic项目中Example文件夹复制到其他的域名下,然后访问 xxx.com/clinet.php 模拟推送api访问结果。

即可在swoole statistic后台中看到统计~


最后推荐大家可以用下我开源的一个基于Swoole4.5+研发的PHP框架。该框架基于注解实现了很多好玩的功能,很适合新人快速上手Swoole扩展。

SW-X框架-专注高性能便捷开发而生的PHP-SwooleX框架​www.sw-x.cn
6cfffef940f18c702423c7c0983b993c.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值