
Tengo dos configuraciones de backend de Laravel en diferentes rutas. y hay un spa en la raíz. ahora quiero configurar un servidor websocket junto con él. aquí está mi sitio web.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 ######################
el location /ws
bloque está tomado de la documentación de laravel websockets.pero este bloque de ubicación genera un error 404 no encontrado.pero esta configuración de nginx no funciona. Mi proyecto de sitio web laravel funciona bien en localhost.
editar
esta es la salida 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)