首頁 > 運維 > Nginx > Laradock中Laravel Octane與WebSocket的nginx怎麼配置

Laradock中Laravel Octane與WebSocket的nginx怎麼配置

WBOY
發布: 2023-05-17 15:22:06
轉載
1291 人瀏覽過

前情描述

laradock中安裝好Laravel Octane後swoole啟動,在nginx中設定埠存取連線失敗,報錯提示502,設定如下:

location /octane {
    proxy_pass http://127.0.0.1:8080;}
登入後複製

原因:Swoole伺服器在Workspace容器中運作;Nginx伺服器在Nginx容器中執行,需要找到Workspace的ip並在nginx中設定。

解決方法

  • docker ps 檢視Workspace容器的id。

  • docker inspect 容器id,找到Networks中的IPAddress

  • 修改nginx設定檔。


    map $http_upgrade $connection_upgrade {
     default upgrade;
     ''      close;}
    
    登入後複製

    upstream ws {
     server 172.22.0.4:9502 weight=5 max_fails=3 fail_timeout=30s;}
    
    登入後複製
    <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">location /ws { set $suffix &quot;&quot;; if ($uri = /index.php) { set $suffix ?$query_string; } proxy_http_version 1.1; 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; proxy_pass http://ws$suffix;}</pre><div class="contentsignin">登入後複製</div></div>
  • 重啟nginx。

設定檔

map $http_upgrade $connection_upgrade {
    default upgrade;
    &#39;&#39;      close;}upstream ws {
    server 172.22.0.4:9502 weight=5 max_fails=3 fail_timeout=30s;}server {

    listen 80;
    listen [::]:80;

    server_name bbs.test;
    root /var/www/laravel/public;
    index index.php index.html index.htm;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }

    location /ws {
        set $suffix "";

        if ($uri = /index.php) {
            set $suffix ?$query_string;
        }

        proxy_http_version 1.1;
        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;

        proxy_pass http://ws$suffix;
    }

    error_log /var/log/nginx/laravel_error.log;
    access_log /var/log/nginx/laravel_access.log;}
登入後複製

以上是Laradock中Laravel Octane與WebSocket的nginx怎麼配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:yisu.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板