Primus js on sub path (sub uri) on Nginx Proxy Server
See original GitHub issueVersion: 3.2.3
Environment:
- Operating system: Mac OSX
- Browser: Crome
- Node.js: v0.12.0
Expected result: Primus should be work on sub path of Nginx.
Actual result: It is falling back to localhost.
Steps to reproduce: I want to use Primus with Node JS server behind Nginx at sub path (or sub uri) as real-time. So I have made changes in nginx.conf as below.
upstream realtime {
ip_hash;
server localhost:1967;
}
location /real-time/ {
proxy_pass http://realtime/;
proxy_redirect off;
proxy_set_header Host $host;
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;
# WebSocket specific
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#
# Specific for comet or long running HTTP requests, don't buffer up the
# response from origin servers but send them directly to the client.
#
proxy_buffering off;
#
# Bump the timeout's so someting sensible so our connections don't
# disconnect automatically. We've set it to 12 hours.
#
proxy_connect_timeout 43200000;
proxy_read_timeout 43200000;
proxy_send_timeout 43200000;
}
Now I am able to get primus.js file at http://localhost/real-time/primus/primus.js. But when I will try make connection as below.
primus = Primus.connect("http://localhost/real-time?some_query_string, {
transformer: 'SockJS'
});
It fall back to localhost as below and getting following error.
GET http://localhost/primus/info?some_query_string&_primuscb=LDur-1u&t=1458021326978 404 (Not Found)
Without Nginx, It works fine using http://localhost:1967. (I am running the node js server on 1967 port.)
How can I properly configure Primus with Nginx? Thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
NginX: Serve application under sub path - proxy - Server Fault
Generally running the app under an URI prefix when the app itself does not expect it is a tricky thing, and the only...
Read more >NodeJS and Primus.io WebSocket opening handshake was ...
It seems to me that you've configured your nginx server incorrectly and that it's blocking WebSocket connections causing a 400 error to be ......
Read more >How to set up reverse proxy with nginx to host express js app ...
I want to host an express js app at ... How to set up reverse proxy with nginx to host express js app...
Read more >primus
There are a lot of real-time frameworks available for Node.js and they all have different ... If you're running your server behind a...
Read more >Ws | npm.io
requires-port, http-proxy-middleware, isomorphic-ws, js-message, rpc-websockets, express-ws, simple-websocket, ccxt, primus, koa-websocket, websocket-
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you configured the pathname to be
/real-time/primus
, your location location in nginx should be/real-time/primus/
.On the client you don’t have to specify the pathname and the
transformer
option is only valid on the server.I think pathname should be also configurable from client. The reason for it is following. Imagine nginx as reverse proxy with following configuration:
So basically nginx will proxy any request from http://myremotedomain.com/ws -> http://localhost:8882 but /ws part of path is actually not sent to local primus server.
If client wants to connect it will:
pathname
option.But here is the problem. Auto generated primus.js client side script has no notion about /ws subpath (which is server from). Only nginx is aware of that subpath and actually strip /ws before proxying request to local server . There is no way with single nginx location how to proxy such a scenario.
Currently only way to @workaround is by adding another nginx location direction
I suggest Primus.connect to obey whole url as is and not only domain part of it as it is now. eg. Primus.connect(’ http://myremotedomain.com/ws/primus’).
Quote from nginx