0

i have two laravel backend setup on different routes. and there is a spa on root. now i want to set a websocket server along with it. here is my website.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 ###################### 

the location /ws block is taken from laravel websockets documentation. but this location block is giving 404 not found error. but this nginx configuration doesn't work. My laravel website project works fine on localhost.

edit

this is the output of lsof -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) 
8
  • Which port is the Laravel listen to? Commented Jul 28, 2021 at 8:12
  • @djdomi are you asking for laravel default http port or websocket port? laravel default port 80 and for websocket it is 6001. Commented Jul 28, 2021 at 9:28
  • show us, lsof -i :80,443,6001 Commented Jul 28, 2021 at 9:50
  • @djdomi i am adding the output in the question edit. Commented Jul 28, 2021 at 10:26
  • maybe You can join thechat to shorten it, but i can only see NGINX running on these 2 ports. - but i see you are running a newer version of lsof so lsof -P -i :80,443,6001 might be updated :) Commented Jul 28, 2021 at 12:11

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.