在 laradock 環(huán)境中使用 laravel-swoole 加速你的 laravel 應(yīng)用

laradock

安裝laravel-swoole

composer require swooletw/laravel-swoole
php artisan vendor:publish --tag=laravel-swoole

開放 workspace 端口

laradock/workspace/Dockerfile 最后添加一行:

EXPOSE 1215

然后重新 build workspace 容器。

修改 nginx 配置

upstream swoole-http {
    server workspace:1215;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {

    listen 80;
    listen [::]:80;

    # For https
    # listen 443 ssl;
    # listen [::]:443 ssl ipv6only=on;
    # ssl_certificate /etc/nginx/ssl/default.crt;
    # ssl_certificate_key /etc/nginx/ssl/default.key;


    server_name study.test;
    root /var/www/laravel-learn/public;
    index index.php index.html index.htm;

    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 $http_host;
        proxy_set_header Scheme $scheme;
        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;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        # IF https
        # proxy_set_header HTTPS "on";

        charset utf-8;

        proxy_pass http://swoole-http$suffix;
    }
}

然后重啟 nginx

修改 laravel env

SWOOLE_HTTP_HOST=workspace
SWOOLE_HTTP_DAEMONIZE=true
SWOOLE_HOT_RELOAD_ENABLE=true

啟動 swoole

php artisan swoole:http start | stop | restart | resload

開發(fā)環(huán)境熱更新

調(diào)整 swoole_http 中 max_request = 1
san swoole:http start | stop | restart | resload


# 開發(fā)環(huán)境熱更新
調(diào)整 swoole_http 中 `max_request = 1`
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容