8 ms·
Nginx-1.4.0 stable version has been released
- aioprisan 14y agothe websocket support is very interesting and useful for node.js projects: http://nginx.org/en/docs/http/websocket.html http://nginx.org/en/docs/http/websocket.html
- atto 14y agoAs a tip to anyone using nginx to proxy websockets: make sure you increase the proxy read timeout for that connection. Otherwise, nginx will drop the (active) connection much sooner than you'd otherwise expect.
- derefr 14y agoIndeed; all the docs I could find referred to the old pre-websockets-support behavior, where you used TCP-passthrough and there was a (hackish) "websocket_read_timeout" property. I ended up going with proxy_read_timeout 31536000; --meaning that a client can hold open a websocket without the server needing to say anything for a year at a time. I'm not sure whether that's a good idea in all cases, though; it means you won't detect silent backend netsplits (i.e. the network cable getting cut to your appserver box without giving it a chance to FIN) since the TCP connection will still look open. The more cautious solution might be to use a lower timeout (120s or so) but to have the server send heartbeats over the websocket when it's not doing anything. (If you're using socket.io, you're already getting this behavior for free; if you're using sock.js, you can enable it.) This breaks down at true scale, though: when you have 100000 idle clients you might want to announce to at any time, but don't usually have anything to say to most of them, sending heartbeats to every client in that pool can saturate your link. A compromise is probably to set the long timeout, but then use a cluster-monitoring service which will push a new config to your load-balancers in response to observed network-toplogy changes.
- atto 14y agoYep. We initially went with a 1 hour timeout — worst case, the client drops every hour, and then immediately reconnects. We actually moved to a heartbeat system recently, because we found issues with spotty connections where we'd have packets lost / delayed (for up to a couple minutes), but the server and client both believed they were connected. Scaling the heartbeat is actually not a big issue. If you're actively using the socket for things, the overhead of that is likely much higher than supporting pings. You'll actually hit port limitations first (if you can support ~65k connected clients per machine), in our experience. 3000 pings a second isn't too bad (that's 100k clients, pinging every 30 seconds or so). You can also change how fast the client is pinging based on client activity.
- derefr 14y ago> You'll actually hit port limitations first (if you can support ~65k connected clients per machine) This isn't actually a limit, by the way. The port limitation is a uniqueness constraint on full (source IP, source port, dest IP, dest port) tuples; it just means one client can't have more than 65k connections open to your server (which tends to trip people up, because they see themselves running into the limit when benchmarking parallelism--because they're sending all the requests from their own computer.) What you'll usually hit first is the open file descriptor ulimit.
- atto 14y agoAh cool. Yep, that's what we did, thanks. edit: I thought too fast. Amfy's reply to you is correct (and what I have seen previously). When proxying with nginx, you use up the ports locally (unless I'm missing something?).
- derefr 14y agoAh, I got confused with what exactly you meant. This is indeed an actual problem, but it's one with an easy solution: you just make each backend process listen on multiple ports, and list them all as separate entries in the nginx's upstream{} section for that backend. One backend with 1024 ports open = 67M connections nginx can make to that backend. Again, you're not "using up" local ports, just (IP/port, IP/port) pairs--so increasing the number of remote ports you want to talk to allows you to make more connections just as well as if you could increase the number of local ports used to talk to them. (This might not be so simple for some servers which expect to only listen on one port; the workaround is to use multiple IPs for the backend server, and make sure the backend process is listening on 0.0.0.0. They don't have to be real IPs--you can just as well do port-forwarding on the backend box from one-IP:lots-of-ports to lots-of-virtual-IPs:one-port. It's simple enough to listen on multiple ports in both Node and Erlang, though, so this probably doesn't matter for most people writing websocket servers.)
- ushi 14y agoThe default proxy_send_timeout is 60s. If you rely on the information about connected clients (chat anyone?), it's way nicer to ping the server every 30s, than to set huge timeouts. If internet connection of the client breaks (mobile anyone?) and the client has no possibility to close the websocket connection, nginx keeps the connection open and you server thinks that there are some clients to talk to. Nice side effect: Your client knows about the disconnect, because the ping fails. EDIT: it's the proxy_send_timeout directive.
- atto 14y agoAgreed. We have a larger window so that we can adaptively ping (when the client isn't very active, we don't ping as often). We're not making chat though. If you do want timeouts like this, an alternative is to handle this on the application layer, and not rely on nginx to drop connections.
- derefr 14y agoEDIT: the parent originally said "proxy_read_timeout", and this comment was in response to that. proxy_read_timeout times out reads from the upstream. It will trigger when a backend server goes AWOL, not when a client falls off the net. If you want to detect client-side disconnection, you want proxy_send_timeout. You can emulate this by having server sent heartbeats with a proxy_read_timeout with the client required to respond to them before the server will send any more, thus going read-silent whenever the client fails to respond, but why not just have the client do the pinging? Then the server doesn't have to say anything in response most of the time.
- ushi 14y ago> but why not just have the client do the pinging? That's exactly what i meant. Sorry if it was unclear. I accidentally switched proxy_send_timeout and proxy_read_timeout.
- adisbladis 14y agoFinally! I have really been looking forward to the SPDY support in stable.
- e1ven 14y agoIt's a very cool thing. One thing you might not have been aware, due to the unusual naming- The 1.3 series is/was perfectly stable for production use. The name referred to API/module stability, more than production-worthy-ness. GL with your deploy!
- JennyZ 14y agoMe too, I just updated on Arch but activating SPDY isn't working so far: nginx[20116]: nginx: [emerg] the "spdy" parameter requires ngx_http_spdy_module in /etc/nginx/nginx.conf:26 Seems the Arch package was built without SPDY support?
- ushi 14y agoAdd --with-http_spdy_module to the configure flags in your PKGBUILD. But expect problems with parallel XHR file uploads in all major browsers.
- JennyZ 14y agoThanks but I'm not going to build it myself, I think it's better for me if I leave that up to the package maintainers ^^
- cerales 14y agoThe Arch package maintainers' job mostly boils down to managing the PKGBUILD. If you get comfortable using ABS your experience with Arch will improve dramatically.
- JennyZ 14y agoSeems the package has been updated again with SPDY support this time (1.4.0-2)
- fourstar 14y agoI've always used Apache but I really want to use nginx for my next project (it's a Node/express app). How should I start? It'll be running on my Ubuntu VPS. Any tips, suggestions, common pitfalls?
- Osiris 14y agoThe only pitfall that I've run into is converting Apache rewrite rules (htaccess) files and getting that into the nginx configuration file. For sure, the configuration file format is different, but it's not terribly complicated.
- lgbr 14y agoThere's really not that much to it. Use nginx that comes from APT and use a unix socket to communicate between node and nginx. I use this code to open a unix socket in production at tmp/socket : https://gist.github.com/lgbr/5453355 https://gist.github.com/lgbr/5453355 And use a configuration like this for nginx (replace /etc/nginx/sites-available/default with this): https://gist.github.com/lgbr/5453375 https://gist.github.com/lgbr/5453375
- mixmastamyk 14y agosudo apt-get install nginx $BROWSER http://wiki.nginx.org/Configuration $EDITOR /etc/nginx/nginx.conf man nginx man upstart sudo start nginx $BROWSER http://localhost:$PORT/
- didip 14y agoIf you use the famous upload module: http://www.grid.net.ru/nginx/upload.en.html http://www.grid.net.ru/nginx/upload.en.html, it no longer works since Nginx 1.3.9. See: https://github.com/vkholodkov/nginx-upload-module/issues/41 https://github.com/vkholodkov/nginx-upload-module/issues/41
- mixedbit 14y agoOne feature I miss the most in nginx is a dynamic loading of modules. I wonder if this is anywhere on a roadmap, or is there some deeper reason for such limitation?
- andyfleming 14y agoWhen will the Ubuntu PPA will be updated?
- sp332 14y agoHere, ask the maintainers: https://launchpad.net/~nginx/+contactuser https://launchpad.net/~nginx/+contactuser
- sahaskatta 14y agoI was about to ask the same thing. The current stable version in PPA is several versions behind.
- pfg 14y agoYou could use the Ubuntu apt repository[0] managed by nginx. I've been using that repository for years, always worked great. New releases get pushed (almost?) instantly. [0]: http://nginx.org/en/linux_packages.html#distributions http://nginx.org/en/linux_packages.html#distributions
- deleted 14y ago[deleted]
- andyfleming 14y agoI'm getting a 504 on http://wiki.nginx.org/ http://wiki.nginx.org/
- nodesocket 14y agoUsing the official YUM repo http://nginx.org/packages/centos/6/$basearch/ http://nginx.org/packages/centos/6/$basearch/ they don't build with the `ngx_http_spdy_module` enabled. Is there a way to get it, without doing a custom compile? I'd like to continue to use the YUM package manager.
- nacs 14y agoFrom http://nginx.org/en/docs/http/ngx_http_spdy_module.html http://nginx.org/en/docs/http/ngx_http_spdy_module.html : "This module is not built by default, it should be enabled with the --with-http_spdy_module configuration parameter." So unless you go with an unofficial binary, you'll have to compile it in yourself.
- oconnore 14y agoOn Ubuntu, there is an "nginx-extras" package with more modules. I don't have a centos machine handy. But really, the burden of a 'custom compile' is small. Nginx configuration is simple, it has minimal dependencies, and it builds quickly. You will need zlib-dev and openssl-dev.
- druska 14y agoChris Lea has a PPA for nginx-devel with SPDY enabled: https://launchpad.net/~chris-lea/+archive/nginx-devel https://launchpad.net/~chris-lea/+archive/nginx-devel
- stock_toaster 14y agograb the spec file, edit, and build. then use yum localinstall. EDIT: looks like spdy (on same port as https) requires openssl >= 1.0.1. centos has 1.0.0. nuts.
- camus 14y ago"So i'm still an apache httpd guy , can you sell me nginx in 3 simple points ?" (actually i'm using it already , i need to sell it to my boss).
- gexla 14y agoYou probably don't need to. Apache is good enough and if you have to sell your boss on using Nginx then you probably don't have enough need to switch. It should sell itself or you are probably just wasting your time. I use Nginx because I find it easier to configure and more lightweight out of the box.
- iso8859-1 14y agoIt's simpler, easier to configure, has event-driven "magic" :). But seriously, you can google this and it doesn't make sense to sell HTTP servers like toothpaste anyway. Just be absolutely sure that you never need the additional features that Apache Httpd provides, and Nginx will probably be a good choice. Read http://stackoverflow.com/a/3635081/309483 http://stackoverflow.com/a/3635081/309483 There is also a linked 100+ vote question, but I think it has too much noise. I'm an Apache guy too. If you know how to configure it, there's not much reason to switch from Apache.
- harshreality 14y agoBeing able to run a site using less memory on average, and much less memory in the worst case (traffic spike for a site running a dynamic language module like mod_php), is a major reason to switch to Nginx from Apache.
- iso8859-1 14y agoApache 2.4 has reduced memory usage, are you sure this still applies? Nobody is forcing you to use mod_php, in fact I'd say it's obsolete. I use PHP-FPM.
- njharman 14y agoIf your using it already, why do you need to sell it?
- mattparlane 14y agoThis page: http://nginx.org/en/docs/http/ngx_http_spdy_module.html http://nginx.org/en/docs/http/ngx_http_spdy_module.html says that the module is experimental. Is that accurate, or have they just not updated it once nginx stable was released?
- pavs 14y agoDoes anyone have a solution to this problem with nginx I have had few times over the years? http://www.howtoforge.com/forums/showthread.php?p=296263#post296263 http://www.howtoforge.com/forums/showthread.php?p=296263#pos... Please note that I am not 100% sure if its nginx related.
- mattparlane 14y agoI see you're running FPM -- I had the same problem, and it turned out to be FPM's worker auto-spawning system. I set it to pm = static and set the number of workers to 50, which is the most I ever need, plus some headroom. Give that a go.
- pavs 14y agoThanks I will give it a shot when I go home, I can only ssh to my server from home computer. You are right the pm is set to dynamic last time I checked, its the default. I will update you on this after observing my server for 24 hours.
- pavs 13y agoJust wanted to update you on this. I switched to another hosting provider (for other reasons) so I ended up working on the server from scratch. The pm is still dynamic because I want to see if I can reproduce the problem again, and if it does I can always try static. Thanks.
- 1SaltwaterC 14y agoI can provide you some pointers as we made it go away. Some data from one of our production virtual hosts: cat access.log.1 | wc -l 1054423 # no static objects served here cat error.log.1 | grep timed For PHP-FPM we use static pm and unix domain sockets. This virtual host if fairly busy with some slow (~200 ms) requests, therefore it uses 96 processes per pool. listen.backlog = -1 in php-fpm.ini for letting the kernel decide the size of the actual connection backlog. UDS is getting filled faster than TCP and nginx starts responding with 502's. Throw net.core.somaxconn = 65535 somewhere in /etc/sysctl.d for increasing the actual backlog since even if you specify a high listen.backlog value, the actual value is truncated to SOMAXCONN. Couple of years ago I wrote an article about stuff like this: http://www.saltwaterc.eu/nginx-php-fpm-for-high-loaded-websites.html http://www.saltwaterc.eu/nginx-php-fpm-for-high-loaded-websi... (shameless plug, I know, but you may get some useful info). As a side note, I am curious how the backend persistency for nginx is playing. Our production still uses the same config since 2011 as it isn't broken, but it may be more efficient.
- xpose2000 14y agoIs this .htaccess to nginx config convertor reliable? http://winginx.com/htaccess http://winginx.com/htaccess Seems like the biggest hurdle to adopting nginx is getting the config in order.