今天小编给大家分享一下Laradock中Laravel Octane与WebSocket的nginx怎么配置的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
前情描述
在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;}
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;}
重启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;}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怎么配置”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。