Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Whats the point of nginx now?#72

Answeredbyghost
Josema asked this question inQ&A
Discussion options

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?

You must be logged in to vote
Answered by ghostFeb 22, 2019

I can't answer what you should or shouldn't do. It's up to you.

Replies: 4 comments 5 replies

Comment options

I can't answer what you should or shouldn't do. It's up to you.

You must be logged in to vote
0 replies
Answer selected
Comment options

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.

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
4 replies
@JhonnyJason
Comment options

"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)?

@the-lstv
Comment options

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.
It logs some stuff to the console on every domain, so I am guessing it's an experimental feature.

You useSSLApp.addServerName(domain, options) to add a certificate, and thenSSLApp.domain(domain) to setup routers for it.
Once you figure out how to work with that its pretty simple to 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.

@JhonnyJason
Comment options

Thank you very much for the starter - seems more like day then weeks ;-)

@Mupli
Comment options

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];
Comment options

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.

You must be logged in to vote
1 reply
@the-lstv
Comment options

HTTP3 support in uWS should be available soon hopefully :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
5 participants
@Josema@JhonnyJason@uasan@the-lstv@Mupli
Converted from issue

This discussion was converted from issue #72 on December 09, 2020 12:45.


[8]ページ先頭

©2009-2025 Movatter.jp