- Notifications
You must be signed in to change notification settings - Fork611
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi, I use to build my projects on top of express.js and nginx. But after discovering this project and seeing that supports compression and SSL not sure if make sense to use nginx anymore. Is ok if I go only with uWebSockets.js or I can lose some features nginx have that uWs.js doesn't? |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
I can't answer what you should or shouldn't do. It's up to you.
Replies: 4 comments 5 replies
-
I can't answer what you should or shouldn't do. It's up to you. |
BetaWas this translation helpful?Give feedback.
All reactions
👎 3
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I am not sure about the performance difference - might be interesting to investigate. However, one important thing is the use of nginx as a reverse proxy for urls with different domains/servernames but resolving to the same IP address. Basically you want nodejs to serve 1 application - uWS makes it faster - but you want nginx to serve multiple applications from a single point of access. |
BetaWas this translation helpful?Give feedback.
All reactions
-
It's correct that you don't need Nginx at all. You don't lose any functionality (there isn't anything special that Nginx does that uWS doesn't). I also migrated from using Nginx+Express to just uWS about a year ago, managing many servers at once. It works flawlessly, only challenge I had in my case was to make uWS handle SSL for multiple domains + wildcards through a single router, but it worked well at the end and was worth it. I use a single uWS server to manage all my web applications, which makes this easier, and for cases where I needed a separate server I made a simple proxy function built into my uWS router. Removing Nginx can make your setup simpler, less bloated and also faster by a small bit. Performance-wise you will most likely see a small improvement since a proxy is just an extra step. The difference won't be significant but it'l be there, so unless you need Nginx for other things, I'd say go for it. I also just realized that this question is over 5 years old. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
"It works flawlessly, only challenge I had in my case was to make uWS handle SSL for multiple domains + wildcards through a single router, but it worked well at the end and was worth it." This is the usecase I am interested in and why I am using nginx - how "well" did it work out in the end? How laborious is this journey (days or > week)? |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Sorry for the late reply, I didnt notice that your post was a reply to my comment. It's actually not difficult (the API already has support for this), just not very well documented and the API isn't very clear/helpful, so I figured it out on my own via trial-and-error. I am not sure if I'm doing it 100% correctly, either way, it works. You use This is roughly how I do it: // Your SSL AppconstSSLApp=uws.SSLApp();functionaddDomain(domain){// Your certificatesSSLApp.addServerName(domain,{key_file_name:`/etc/letsencrypt/live/${domain.replace("*.","")}/fullchain.pem`,cert_file_name:`/etc/letsencrypt/live/${domain.replace("*.","")}/privkey.pem`})// Here, you setup routers for the domain// In my case I route everything through a single function, which might not be what you are looking forSSLApp.domain(domain).any("/*",resolve)// .ws("/*", {}) ...}functionresolve(res,req){// Handles HTTPS requests for all domains + subdomainsres.end()}// Domains to handle, if you want it to be done automaticallyfor(letdomainof["example.com","another-domain.net"]){addDomain(domain)// In the case of wildcard certificates - to handle all subdomains tooaddDomain("*."+domain)}SSLApp.listen(443); It should also be possible to handle missing domains on the fly: SSLApp.missingServerName((hostname)=>{addDomain(hostname)}) However, this didnt work well for me as far as I remember. It is also an issue that setting up the router when a request is already being processed isn't a very good idea. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
Thank you very much for the starter - seems more like day then weeks ;-) |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I have solve it with the manual implementation. My appName/domain is able now to get proper router etc. I've checked the performance and it is same for both solutions. consth=req.getHeader("host");consthindex=h.indexOf(":");// in case you are using port "myapp.local:3000"consthost=hindex>0 ?h.slice(0,hindex) :h;constappName=this.hostNamesToApp[host]; |
BetaWas this translation helpful?Give feedback.
All reactions
-
Over these 5 years, there is only one reason why Nginx is needed, it is HTTP 2 and HTTP 3, uWS works only on HTTP 1.1, this means that all your requests in 1 connection are executed sequentially, without multiplexing, this is important for performance. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
HTTP3 support in uWS should be available soon hopefully :) |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #72 on December 09, 2020 12:45.