I am working on a web-socket project and i want web-socket cowboy server to listen to 8080 port but to forward messages to another port . Can I do that ?
any help is appreciated
what do you mean by forward messages to another port? cowboy's handler is handling the messages that arrive on your websocket. You can take those an redirect them anywhere you like. However I think what you are really after is a proxy that fronts your cowboy. If that is the case you should consider nginx as a front. Once you installed it you can provide this config:
http {
...
server {
listen 443
...
location ~ ^/myws/
{
proxy_pass http://127.0.0.1:8080 ;
proxy_http_version 1.1 ;
proxy_set_header Upgrade $http_upgrade ;
proxy_set_header Connection "upgrade" ;
proxy_connect_timeout 60 ;
proxy_read_timeout 86400 ;
proxy_send_timeout 86400 ;
proxy_ignore_client_abort off ;
proxy_redirect off ;
}
...
}
....
}
this will enable you to run cowboy listening on any port you like (8080 in your example) while letting nginx take care of you SSL needs while forwarding websocket requests to cowboy. The client can connect #
wss://{your server}/myws
If you do not need SSL address will be
ws://{your server}/myws
and listen port in the config above needs to change to 80.
Related
I am hosting a web application via a home server. I have my Cloudflare DNS A record pointed to my public ip and my firewall is off. I am using cloud flare for SSL.
My app is running on local host (127.0.0.1) port 1624.
I am using nginx. My server name is my public ip and listen is port 80.
My reverse proxy is pointed at 127.0.0.1:1624.
I have port 80 open on my router as well.
For some reason I am not able to connect to my website. What could be causing this?
The developer of the web app has told me to use my domain name for the server name and keep the port as default 80 while pointing the reverse proxy to 127.0.0.1:1624.
My nginx conf:
server
{
server_name {mypublicip};
#server_name {mydomainname};
listen 80;
location / {
proxy_pass http://127.0.0.1:1624; # my web app proxy
proxy_http_version 1.1;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Router Settings:
I've tried:
Nginx conf -
server_name > domain NAME
server_name > public ip
My app is working when I go to 127.0.0.1:1624 just not my domain.
You should configure port forwarding on your router - so that all packets coming on port 80 of the public IP on your router will be forwarded to port 80 of your local PC (which probably has an internal IP address in a 192.168.xx.yy range). Then your nginX should listen on port 80 at that 192.168.xx.yy address on your PC and proxy_pass to 127.0.0.1:1624 where your application is listening.
IF you don't do this - packets will end up on the router instead of at nginX in your local PC.
Trying to get the two to work together. Is there something I'm missing or way to debug why it's not working?
Edited .devilbox/nginx.yml as suggested here although trying to contain it to path: wsapp
---
###
### Basic vHost skeleton
###
vhost: |
server {
listen __PORT____DEFAULT_VHOST__;
server_name __VHOST_NAME__ *.__VHOST_NAME__;
access_log "__ACCESS_LOG__" combined;
error_log "__ERROR_LOG__" warn;
# Reverse Proxy definition (Ensure to adjust the port, currently '8000')
location /wsapp/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://php:6001;
}
__REDIRECT__
__SSL__
__VHOST_DOCROOT__
__VHOST_RPROXY__
__PHP_FPM__
__ALIASES__
__DENIES__
__SERVER_STATUS__
# Custom directives
__CUSTOM__
}
Installed laravel-websockets and configured to use '/wsapp'
Visit the dashboard to test:
https://example.local/laravel-websockets
But console has error:
Firefox can’t establish a connection to the server at
wss://example.local:6001/wsapp/app/a558686cac00228eb003?protocol=7&client=js&version=4.3.1&flash=false.
2 pusher.min.js:8:6335 The connection to
wss://example.local:6001/wsapp/app/a558686cac00228eb003?protocol=7&client=js&version=4.3.1&flash=false
was interrupted while the page was loading. pusher.min.js:8:6335
I've Created a Setup that works...
first you need 2 domains in devilbox...
For you Laravel App (example.local)
For you Laravel Websocket (socket.example.local)
on your socket.example.local directory...
create htdocs and .devilbox here you'll add your nginx.yml file
when you try to connect to your socket.
don't use the port anymore...
and don't isolate the socket to /wsapp anymore...
use socket.example.local in .env PUSHER_HOST value
run your laravel websocket on example.local...
visit /laravel-websockets dashboard... remove the port value then click connect
I don't suggest you'll serve your socket in /wsapp because it's hard to configure nginx to serve 2 apps... (it's hard for me, maybe someone more expert on nginx can suggest something regarding this setup)
but that's my solution... if you didn't understand, please do comment
My web stack is composed of (nginx (port: 29090) -> tomcat)
nginx act as reverse proxy, and tomcat host 2 webapps1. For Authentication (using netflix zuul ) - running on port 29091 2. SensorThings API server - running on port 29101
This below request is passed using zuul.route.sensor.url=http://localhost:29090/sensor-internal
Below is nginx.conf block
location /sensor-internal/ {
include cors_support;
rewrite ^(/sensor/)(.*)$ SensorThingsServer-1.0/v1.0/$2 break;
proxy_redirect off;
proxy_set_header Host $host;
rewrite_log on;
}
I want to replace the URL
http://localhost:29090/sensor/xxxx(n)/yyyy(m)
to
http://localhost:29101/SensorThingsServer-1.0/v1.0/xxxx(n)/yyyy(m)
See change in port and replace sensor with STS-1.0/v1.0/
I believe the above block will not work for port change. Please guide.
You should describe separate location /sensor/ and perform rewriting there, because location /sensor-internal/ you have defined does not serve /sensor/* request.
location /sensor/ {
rewrite ^/(/sensor/)(.*)$ http://localhost:29101/SensorThingsServer-1.0/v1.0/$2 break;
rewrite_log on;
}
I am using netty 4.0.20 I want to create different websocket servers on the same port using different urls
for example,
wss://localhost:1234/PathA
wss://localhost:1234/PathB
wss://localhost:1234/PathC
is that possible?
Yes, this is possible with using reverse proxying, which can be done with Nginx.
This will require one additional server in your setup.
First you have to setup each server to listen to a different port and then you need the front end server to listen to your desired public port (in your case, this is 1234).
So lets say you have the following servers
Nginx listening at 0.0.0.0:1234
Netty that serves /PathA and listens at 0.0.0.0:1235
Netty that serves /PathB and listens at 0.0.0.0:1236
Netty that serves /PathC and listens at 0.0.0.0:1237
Now what you have to do is write an Nginx configuration file that will upgrade the connection from HTTP to Websocket and then reverse proxy each path to its corresponding server. An example configuration file that could do the job for you is the following.
{
listen 1234;
server_name localhost;
location ~PathA/$ {
proxy_pass http://localhost:1235;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "upgrade";
}
location ~PathB/$ {
proxy_pass http://localhost:1236;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "upgrade";
}
location ~PathC/$ {
proxy_pass http://localhost:1237;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "upgrade";
}
}
I have some webs that are served by nginx with SSL (443) without problems.
Now, I have the web mail serving SSL on port 444, but I want nginx to proxy from 80 to 444 when webmail.mydomain.com reaches.
I've tried some config but no one of them worked. This is the last one ...
thanks,
m.
server {
listen 80;
server_name webmail.mydomain.com;
root /etc/nginx/sites-available/webmail/;
access_log /etc/nginx/sites-available/nginx.log;
client_max_body_size 50M;
location / {
proxy_pass http://192.168.1.2:444/;
proxy_redirect https://192.168.1.2:444;
}
}
I'm doing something similar. What worked for me was to define an upstream server on the same box
upstream some_name {
server 127.0.0.1:4000;
}
and then doing
proxy pass http://some_name;
Obviously my ports are different