- 安裝 laravel swoole 擴充套件
composer require swooletw/laravel-swoole
註冊providers
app.php 的 providers 陣列中加上 SwooleTW\Http\LaravelServiceProvider::class
釋出配置檔案資源
php artisan vendor:publish --provider="SwooleTW\Http\HttpServiceProvider"
如果釋出資源報錯 我的解決辦法是
php artisan vendor:publish
瀏覽當前可釋出的資源 選擇需要使用的即可
啟動命令
php artisan swoole:http start|stop|restart|reload
Nginx代理Swoole
由於 swoole_http_server對Http協議的支援並不完整 建議僅作為應用伺服器 並且在前端增加Nginx作為代理
配置 nginx.conf裡的server:
server {
listen 80;
server_name your.domain.com;
root /path/to/laravel/public;
index index.php;
location = /index.php {
# Ensure that there is no such file named "not_exists"
# in your "public" directory.
try_files /not_exists @swoole;
}
location / {
try_files $uri $uri/ @swoole;
}
location @swoole {
set $suffix "";
if ($uri = /index.php) {
set $suffix "/";
}
proxy_set_header Host $host;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# IF https
# proxy_set_header HTTPS "on";
proxy_pass http://127.0.0.1:1215$suffix;
}
}
原文地址:Laravel8使用swoole來取代nginx作為http伺服器 - 暖暖-程式媛的文章 - 知乎
zhuanlan.zhihu.com/p/269911276
本作品採用《CC 協議》,轉載必須註明作者和本文連結