Home > PHP Framework > Laravel > Share the nginx configuration of Laravel Octane and WebSocket in Laradock

Share the nginx configuration of Laravel Octane and WebSocket in Laradock

藏色散人
Release: 2023-02-22 19:58:41
forward
1651 people have browsed it

This article brings you relevant knowledge about Laravel, which mainly records the nginx configuration of Laravel Octane and WebSocket in Laradock. For those who are interested, take a look below. I hope it will be helpful to you.

Share the nginx configuration of Laravel Octane and WebSocket in Laradock

docker Installation of laradock and Laravel Octane will not be described in detail here.

Previous description

After installing Laravel Octane in laradock, swoole is started, and the port access connection configuration in nginx fails. Error message 502, the configuration is as follows:

location /octane {
    proxy_pass http://127.0.0.1:8080;}
Copy after login

Cause: Swoole server runs in the Workspace container; Nginx server runs in the Nginx container, you need to find the IP of Workspace and configure it in nginx.

Solution

  • docker ps View the id of the Workspace container.

  • docker inspect container id and find IPAddress in Networks.

  • Modify the nginx configuration file.

    map $http_upgrade $connection_upgrade {
     default upgrade;
     ''      close;}
    Copy after login
    upstream ws {
     server 172.22.0.4:9502 weight=5 max_fails=3 fail_timeout=30s;}
    Copy after login
    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;}
    Copy after login
  • Restart nginx.

Configuration file

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      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;}
Copy after login

Recommended study: "laravel video tutorial"

The above is the detailed content of Share the nginx configuration of Laravel Octane and WebSocket in Laradock. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template