brewlin / swoole-im

基于swoole开发的在线聊天平台,前端集成layerim框架,swoole基于eayswoole框架,异步连接池,多进程,异步任务,独立httperserver api,websocket推送,重构使用swoft-cloud 进行微服务架构
http://im.brewlin.com
142 stars 41 forks source link

nginx +swoole 配置端口转发不成功,求指点 #3

Open widthhieght opened 5 years ago

widthhieght commented 5 years ago

想让项目跑起来,于是按照步骤进行安装,但是启动服务失败,nginx配置也查了各种资料还是不行,请指教

php版本

[root@VM_0_15_centos im]# php -v
PHP 7.2.14 (cli) (built: Jan 29 2019 12:00:38) ( NTS )

php扩展:
[root@VM_0_15_centos im]# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mongodb
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
redis
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
swoole
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
zlib

swoole配置:

[root@VM_0_15_centos im]# php --ri swoole

swoole

swoole support => enabled
Version => 2.0.8
Author => tianfeng.han[email: mikan.tenny@gmail.com]
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async http/websocket client => enabled
Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled

Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

项目目录:

[root@VM_0_15_centos im]# ls
App            composer.lock  Config.php           easyswoole.install  index.php  makefile   RedisKeys.txt  Temp
composer.json  Conf           EasySwooleEvent.php  img                 Log        README.md  talk.sql       vendor

Config.php 配置:

<?php
/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2017/12/30
 * Time: 下午10:59
 */

return [
    'MAIN_SERVER'=>[
        'HOST'=>'0.0.0.0',
        'PORT'=>9501,
        'SERVER_TYPE'=>\EasySwoole\Core\Swoole\ServerManager::TYPE_WEB_SOCKET_SERVER,
        'SOCK_TYPE'=>SWOOLE_TCP,//该配置项当为SERVER_TYPE值为TYPE_SERVER时有效
        'RUN_MODEL'=>SWOOLE_PROCESS,
        'SETTING'=>[
            'task_worker_num' => 2, //异步任务进程
            'task_max_request'=>10,
            'max_request'=>2500,//强烈建议设置此配置项
            'worker_num'=>2,
            'document_root' => '/website/swoole-im/Public',  // 静态资源目录
            'enable_static_handler' => true,
//            'heartbeat_idle_time' => 60,
//            'heartbeat_check_interval' => 20,
        ],
    ],
    'DEBUG'=>true,
    'TEMP_DIR'=>EASYSWOOLE_ROOT.'/Temp',
    'LOG_DIR'=>EASYSWOOLE_ROOT.'/Log',
    'EASY_CACHE'=>[
        'PROCESS_NUM'=>3,//若不希望开启,则设置为0
        'PERSISTENT_TIME'=>5//如果需要定时数据落地,请设置对应的时间周期,单位为秒
    ],
    'CLUSTER'=>[
        'enable'=>false,
        'token'=>null,
        'broadcastAddress'=>['255.255.255.255:9556'],
        'listenAddress'=>'0.0.0.0',
        'listenPort'=>9556,
        'broadcastTTL'=>5,
        'serviceTTL'=>10,
        'serverName'=>'easySwoole',
        'serverId'=>null
    ],
    'MYSQL'=>[
        'HOST'=>'隐藏一下',
        'USER'=>'隐藏一下',
        'PASSWORD'=>'隐藏一下',
        'DB_NAME'=>'talk'
    ],

    'REDIS' => [
        'host' => '隐藏一下', // redis主机地址
        'port' => 6379, // 端口
        'serialize' => false, // 是否序列化php变量
        'auth' => '隐藏一下', // 密码
        'pool' => [
            'min' => 5, // 最小连接数
            'max' => 100 // 最大连接数
        ],
        'errorHandler' => function(){
            return null;
        }
    ],

    'database' => [
        // 数据库类型
        'type'            => 'mysql',
        // 服务器地址
        'hostname'        => '隐藏一下',
        // 数据库名
        'database'        => 'talk',
        // 用户名
        'username'        => '隐藏一下',
        // 密码
        'password'        => '隐藏一下',
        // 端口
        'hostport'        => '3306',
        // 数据库表前缀
        'prefix'          => '',
        // 是否需要断线重连
        'break_reconnect' => true,
    ],

    'setting' => [
        'token_salt' => 'gye76qwei23eq',
        'WebSocketControllerPath' => 'App\WebsocketController\\',
        'cache_name' => [
            'token_user' => 'user:token:%s:data',                           //  token   => user 信息, 用户登录时创建
            'number_userOtherInfo' =>'userOtherInfo:%s:number:data',        //  number  => fd,token 等信息,用户登录时创建
            'fd_token' => 'fd:%s:data',                                     //  fd => token,    用户登录时创建
            'friend_req' => 'friend:fromNumber:%s:data',                    //  from_num => to_num,发送好友请求时创建,对方拒绝或同意时销毁
            'group_number_fd' => 'group:number:%s:data',                    //  gnumber => fds,创建新群组时创建
        ],
    ]
];

nginx 配置:

server{
        listen 80;
        server_name im.itsideline.com;

        location / {
                root /home/www/im;
                index index.html index.htm index.php;
                if (!-e $request_filename) {
                        proxy_pass http://127.0.0.1:9501;
                }
        }
}

开启服务报错:

[root@VM_0_15_centos im]# php index.php start
  ______                          _____                              _
 |  ____|                        / ____|                            | |
 | |__      __ _   ___   _   _  | (___   __      __   ___     ___   | |   ___
 |  __|    / _` | / __| | | | |  \___ \  \ \ /\ / /  / _ \   / _ \  | |  / _ \
 | |____  | (_| | \__ \ | |_| |  ____) |  \ V  V /  | (_) | | (_) | | | |  __/
 |______|  \__,_| |___/  \__, | |_____/    \_/\_/    \___/   \___/  |_|  \___|
                          __/ |
                         |___/

EasySwoole framework Version 2.0.2

listen address      0.0.0.0
listen port         9501
worker num          2
task worker num     2
run at user         root
daemonize           false
debug enable        true
swoole version      2.0.8
swoole pid          21696
loading data from file at process easySwoole_Cache_Process_0
loading data from file success at process easySwoole_Cache_Process_0
loading data from file at process easySwoole_Cache_Process_1
loading data from file success at process easySwoole_Cache_Process_1
loading data from file at process easySwoole_Cache_Process_2
loading data from file success at process easySwoole_Cache_Process_2
PHP Fatal error:  Uncaught Error: Call to a member function getObj() on null in /home/www/im/App/Service/RedisPoolService.php:23
Stack trace:
#0 /home/www/im/App/Service/UserCacheService.php(142): App\Service\RedisPoolService->__construct()
#1 /home/www/im/App/Sock/Parser/OnClose.php(80): App\Service\UserCacheService::getTokenByFd(1)
#2 /home/www/im/App/Sock/Parser/OnClose.php(28): App\Sock\Parser\OnClose->getInfoByFd()
#3 /home/www/im/EasySwooleEvent.php(75): App\Sock\Parser\OnClose->close()
#4 [internal function]: EasySwoole\EasySwooleEvent::EasySwoole\{closure}(Object(Swoole\WebSocket\Server), 1, -1)
#5 /home/www/im/vendor/easyswoole/easyswoole/src/Core/Component/Invoker.php(56): Swoole\Coroutine::call_user_func_array(Object(Closure), Array)
#6 /home/www/im/vendor/easyswoole/easyswoole/src/Core/Swoole/ServerManager.php(137): EasySwoole\Core\Component\Invoker::callUserFuncArray(Object(Closure), Array)
#7 [internal function]: EasySwoole\Core\Swoole\ServerManager->EasySwoole\Core\Swoole\{closure}(Object(Swoole\WebSocket\Server in /home/www/im/App/Service/RedisPoolService.php on line 23

访问域名也会包502 ... 请问这该如何进行了...

brewlin commented 5 years ago

这个是前后端分离的 前端代码不在这个里面

brewlin commented 5 years ago

有个重构版本 micro-service-im 用swoft重构的后端 https:/github.com/Lxido/micro-service-im chat-view 是前端 https://github.com/Lxido/chat-view.git 这个在我的仓库里有

brewlin commented 5 years ago

有两个演示地址 chat.huido.site im.huido.site

brewlin commented 5 years ago

不需要转发 只要服务能启动就行 接口访问是这样的 :http://talk.huido.site:8080/api/im/chat/record/read 前端是 走的nginx
接口是直接走的 swoole http服务

brewlin commented 5 years ago

swoole 没启动 你看看 你编译swoole的时候需要加上 异步redis配置 ,--async-enabl-redis 类似这个 具体去官网查

widthhieght commented 5 years ago

好的 我再研究一下,非常感谢您的及时解答