1、安装Swoole扩展 (自行安装)
2、laravel 安装laravel-swoole组件
https://github.com/swooletw/laravel-swoole
composer require swooletw/laravel-swoole
然后,添加服务提供者:
如果你使用 Laravel ,在 config/app.php 服务提供者数组添加该服务提供者:
作者:小马在途_8bde
链接:https://www.jianshu.com/p/00e166f21656
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
[
'providers' => [
SwooleTW\Http\LaravelServiceProvider::class,
],
]
3、启动
现在,你可以执行以下的命令来启动 Swoole HTTP 服务。
/usr/local/php/bin/php artisan swoole:http start
然后你可以看到以下信息:
Starting swoole http server...
Swoole http server started: <http://127.0.0.1:1215>
现在可以通过访问 http://127.0.0.1:1215 来进入 Laravel 应用
laravel-swoole 命令
# 启动
/usr/local/php/bin/php artisan swoole:http start
# 重启
/usr/local/php/bin/php artisan swoole:http restart
# 重载
/usr/local/php/bin/php artisan swoole:http reload
# 停止
/usr/local/php/bin/php artisan swoole:http stop
# 查看服务信息
/usr/local/php/bin/php artisan swoole:http infos
4、配合ngnix使用
gzip on;
gzip_min_length 1024;
gzip_comp_level 2;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml;
gzip_vary on;
gzip_disable "msie6";
upstream labs {
# Connect IP:Port
server 127.0.0.1:1215 weight=5 max_fails=3 fail_timeout=30s;
keepalive 16;
}
server {
listen 80;
server_name www.xxx.com;
root /data/www/labs/public/;
access_log /var/log/nginx/xxx.cn.access.log main;
error_log /var/log/nginx/xxx.cn.error.log;
autoindex off;
index index.html index.htm;
location / {
try_files $uri @laravels;
}
location @laravels {
# proxy_connect_timeout 60s;
# proxy_send_timeout 60s;
# proxy_read_timeout 120s;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header Server-Protocol $server_protocol;
proxy_set_header Server-Name $server_name;
proxy_set_header Server-Addr $server_addr;
proxy_set_header Server-Port $server_port;
proxy_pass http://labs;
proxy_set_header HTTPS "on";
}
}
在宝塔中可重新添加站点来配置,需设置为纯静态站点,在面板中配置反向代理后,再次点击编辑配置,添加一行:
proxy_set_header HTTPS "on";
这样被代理的站点就能透过HTTPS访问,而不会默认HTTP
最终,可透过supervisor来守护进程,因为Swoole已经有多线程,所以只需要开一个进程即可
网友评论