
eu tenho duas configurações de backend laravel em rotas diferentes. e há um spa na raiz. agora quero definir um servidor websocket junto com ele. aqui está meu site.conf
############## block-4 : multiple subdirectory testing ############
server {
listen 80;
# server_name abc.xyz;
server_name _;
root /var/www/html/abc.xyz;
# root /var/www/html;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.html index.php;
location / {
# root /var/www/html/abc.xyz;
try_files $uri /index.html ;
}
charset utf-8;
location = /favicon.ico {
access_log off; log_not_found off;
}
location = /robots.txt {
access_log off; log_not_found off;
}
# error_page 404 /index.php;
############## block-4 : multiple subdirectory testing ############
server {
listen 80;
# server_name abc.xyz;
server_name _;
root /var/www/html/abc.xyz;
# root /var/www/html;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.html index.php;
location / {
# root /var/www/html/abc.xyz;
try_files $uri /index.html ;
}
charset utf-8;
location = /favicon.ico {
access_log off; log_not_found off;
}
location = /robots.txt {
access_log off; log_not_found off;
}
# error_page 404 /index.php;
# BACKEND location rewrite instructions
location /backend {
alias /var/www/html/abc.xyz/backend;
try_files $uri $uri/ @backend;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
}
}
location @backend {
# rewrite /backend/(.*)$ /backend/index.php?/$1 last;
rewrite ^/backend/(.*)$ /backend/index.php last;
}
# end of the BACKEND location
# BACKEND location rewrite instructions
location /api {
alias /var/www/html/abc.xyz/api;
try_files $uri $uri/ @api;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
}
}
location @api {
rewrite /api/(.*)$ /api/index.php?/$1 last;
}
# end of the BACKEND location
# phpmyadmin rewrite rules.
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
# end of phpmyadmin block here.
# web socket configuration here
location /ws* {
proxy_pass http://127.0.0.1:6001;
proxy_set_header Host $host;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_redirect off;
# Allow the use of websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# end of websocket configuration
location ~ /\.(?!well-known).* {
deny all;
}
}
############# end block-4 ######################
o location /ws
bloco é retirado da documentação do laravel websockets.mas este bloco de localização está apresentando o erro 404 não encontrado.mas esta configuração do nginx não funciona. Meu projeto de site laravel funciona bem no localhost.
editar
esta é a saída delsof -i :80,443,6001
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php 414490 root 5u IPv4 5974385 0t0 TCP *:x11-1 (LISTEN)
php 414490 root 6u IPv4 5991457 0t0 TCP localhost.localdomain:x11-1->localhost.localdomain:35684 (ESTABLISHED)
nginx 415533 root 6u IPv4 5990824 0t0 TCP *:https (LISTEN)
nginx 415533 root 7u IPv4 5990825 0t0 TCP *:http (LISTEN)
nginx 415534 www-data 6u IPv4 5990824 0t0 TCP *:https (LISTEN)
nginx 415534 www-data 7u IPv4 5990825 0t0 TCP *:http (LISTEN)
nginx 415535 www-data 6u IPv4 5990824 0t0 TCP *:https (LISTEN)
nginx 415535 www-data 7u IPv4 5990825 0t0 TCP *:http (LISTEN)
nginx 415536 www-data 6u IPv4 5990824 0t0 TCP *:https (LISTEN)
nginx 415536 www-data 7u IPv4 5990825 0t0 TCP *:http (LISTEN)
nginx 415537 www-data 6u IPv4 5990824 0t0 TCP *:https (LISTEN)
nginx 415537 www-data 7u IPv4 5990825 0t0 TCP *:http (LISTEN)
nginx 415538 www-data 6u IPv4 5990824 0t0 TCP *:https (LISTEN)
nginx 415538 www-data 7u IPv4 5990825 0t0 TCP *:http (LISTEN)
nginx 415539 www-data 6u IPv4 5990824 0t0 TCP *:https (LISTEN)
nginx 415539 www-data 7u IPv4 5990825 0t0 TCP *:http (LISTEN)
nginx 415539 www-data 8u IPv4 5985866 0t0 TCP linux:https->157.42.56.21:55728 (ESTABLISHED)
nginx 415539 www-data 12u IPv4 5985868 0t0 TCP localhost.localdomain:35684->localhost.localdomain:x11-1 (ESTABLISHED)