Nginx for Developers: An Introduction
carrot.is
carrot.is
http://tech.pro/tutorial/1335/devops-for-dummies-vps-configu...
It teaches you how to setup a DigitalOcean (or any other) VPS from scratch to host N amount of Rails applications using Nginx and Passenger. It took me some time to get things working properly and I distilled it into this short article that holds your hand and takes you from A to Z.
Your current instructions are predicated on success. By verifying your new user login and sudo capability before logging out as root (rebooting), you can fix typos or other Bad Things. Not that I would ever make a typo while editing sudoers. ;-)
By safe, I mean in the context of the server getting hacked. I know people wouldn't bother but I'd rather at least feel a tiny bit safe. I'm going with a VPS (Digital Ocean) too so I can slowly learn all these things.
I'm _not_ a devops guy. Following my guide you _will_ get a running production server but I've only distilled things from other blogs I've hunted on the web. I would make sure I hire someone who actually does this for a living before putting production things on something I configured.
So feel safe, but cautiously safe - I'm not a guru.
And not to mention, how these providers are ddosing and hacking one another regularly.
With sudo and only keys based access, the attacker will need to get a copy of the key (barring any new problems with key generation, like the Debian ssl bug) and the password needed for sudo access (or the root password, for su -).
As other's have said, use visudo (possibly with "EDITOR=nano visudo) -- to avoid leaving your sudoers file in a broken state.
An as others mentioned -- make sure you can login and sudo before you log out of the root shell...
man visudo for more info.
A) Solidify what I had learned by putting it into writing.
B) Help others avoid my dumb mistakes.
So if it helps people I'm all for it. :)
This is one of my other favorite articles: http://docs.ngx.cc/en/latest/topics/tutorials/config_pitfall...
Some good introductory stuff here as well: http://pineapple.io/resources/tagged/nginx
See Muphry's law. :)
cgi.fix_pathinfo = 0I have been complaining about this for years!
On FreeBSD and all my client's sites (whether they run Linux or what), I always set mine to include sites/*.conf and delete those apache-isms.
Hrm, looking now, a2ensite is 340 lines long...
It is my experience from years of administration that `ln` and `rm` (or perhaps `mv`) are the only commands necessary to work with the directories without the scripts.
[1] https://github.com/h5bp/server-configs/tree/master/nginx
The Internet has no default port; 80 is for HTTP. If the port is omitted, then the default for the scheme[1] is assumed.
</pedant>
nginx -t (test your configuration)
nginx -s reload (reload your configuration)
Also I prefer "nginx -s restart".
The reason it's as such is because of what @timroman said in his reply, but if this method is no different and scales better no reason not to use it instead.
I just wish the article talked about using reload as well as restart and when to use them.
[1] On FreeBSD, we just use `killall -HUP nginx` to reload; your distro will probably send HUP to the master process' PID
I'm using it at http://www.utterson.me to serve up static Jekyll blogs on a subdomain.
I may be wrong, but I don't think Apache can do this (it can do regex but you don't get a variable).
[1] http://nginx.org/en/docs/http/server_names.html#regex_names
active.site.com.ON
another.active.com.ON
not.active.comIm surprised to see this on the frontpage, it is less than basics in anything any hacker worth its name can do.
You're just as surprised as we are to see it on the frontpage!
Many other developers, we assumed, would not be as familiar with ops at first, and would prefer more of a basic introduction that walks through the steps and explains things clearly.
On-topic: Thank you for this. I am going to purchase a DO box this weekend and play around with nginx instead of apache. For some reason when I last tried to use nginx, I could not get location {} to work. Granted it was some time ago.
Does anyone have any resources on nginx as a load balancer?
Another note, the share button at the bottom (just pushed a minute ago so hard refresh if it's cached) is from this plugin we put together and have been enjoying so far: https://github.com/carrot/share-button
Glad you enjoyed the article! Let us know if you run into any trouble, happy to help or add debugging techniques etc
EDIT: Updated, should work great on mobile devices now
We had very very bad experience with them, file-system corruption, hardware failures.
And we are still unable to recover all our data. And so far, no hope!
They don't answer any of the questions properly, my team is very upset. We felt, they don't have much technical expertise in managing servers.
DO might be okay for testing and learning, but never use them for any production setups.
Update: we are still struggling to get our data back. No hopes so far.
We shall write a detailed blog post on the whole experience with Digital Ocean.
I can't speak to using it to store lots of not-backed-up files or running a gigantic production server, but for learning about syops it works great, to get back to the purpose of this article.
I really just want to practice setting up and tearing down configurations. I think DO will be a good choice for this.
I actually transitioned all my apps off any other PAAS platforms (mostly nodejitsu, timed nicely with their 3x price increase) and am now hosting everything I run off a single $5 digital ocean box, which actually is saving me a bit of money, and deploys are a lot smoother. The company I work at, Carrot, is also hosting all of carrot.is on a $5 DO box, including this article, which has had no issues coping with the 600+ people on site at a time that have come with this HN blitz.
I'm not too worried about data losses tho, we do regular offsite backups.
They do more granular level monitoring to detect faulty hardware early and replace them faster.
Also greater technical support, having used both of them previously.
Just because you didn't perform backups, it doesn't mean that you should blame the host.
Even the best-of-the-best hosts will fail, but thing to consider is how fast can they resolve issues and are they proactively trying to improve.
We were not aware of your article at all, and if it's "basically a copy" it was entirely coincidental. I think the way you're looking at is very negative though -- any and all efforts to improve understanding of a great and powerful dev tool I think are a positive thing for the community.
I'd love to see your article too, could you link to it?
The article I mentioned can be found here: http://blog.martinfjordvald.com/2010/07/nginx-primer/
I was more surprised than depressed about the upvotes for the current article. It really makes me wonder if the technical level of the audience here hasn't declined substantially. The current article is well written but it's aimed at a "Dummies" rather than developer level.
Since this kind of article still gathers this amount of popularity 3 years later I actually do think it's a problem of the documentation.
As for your goals of connecting NginX to serve your Lua project, well that's quite simple really. Unlike Apache or Lighttpd, NginX is not an application server. NginX is only a reverse proxying HTTP server that speaks HTTP, FastCGI, and UWSGI. To connect your Lua application to NginX, your Lua application will either need to speak HTTP, FastCGI, or UWSGI. I don't know anything about Lua so I can't really help you figure out which is best, but in terms of setting up with NginX, it mostly just changes which flavor of pass you will use.
It is pretty easy once you get started...
Also, if you're reading this article you probably don't need the slightly better performance/throughput of nginx. Nginx's configuration is just terrible. You can cause segfaults and all sorts of unexpected behavior with the If directive[2]. And who came up with the idea that rewrite[3] should sometimes redirect instead of rewriting?
If the replacement string begins with http:// then the client will be redirected, and any further rewrite directives are terminated.
Apache's configuration might be ugly and unwieldy and the community might be horribly infested, but at least the configuration makes sense. Lighttpd has none of the above problems, though.
[1] http://superuser.com/questions/93437/
NginX's configuration is beautiful, elegant, and concise. It kicks the ever living crap out of configuring Apache or Lighttpd (the two other HTTPd's I have extensive experience with). It seems so strange, because it's different.
NginX's configuration language is declarative. If is imperative and actually using if inside locations in NginX creates an inner location and executes a mini language to process.
14:42 <+merlincorey> !ifisevil
14:42 < ngxbot> please see above
Please see http://wiki.nginx.org/IfIsEvil for more about that in particular.Finally, I have to disagree with OP... NginX has great documentation, written by Igor himself initially (and edited by the community) available here: http://nginx.org/en/docs/
NginX's configuration is declarative.
The reason the imperative if was given powers beyond its means was because people clamored for the feature.
The reason it's still there is because removing it would break some working configurations that use if.
If you don't have experience with declarative programming and you think in terms of imperative programming, it might seem "horrible behavior", but actually, it's what is to be expected from mixing the two paradigms in the way it is being mixed.
The real wart is under the hood where-in location based if's are converted to sub-locations. This is where many problems related to IfIsEvil stem from.
No, the problem is not that I haven't read the page. I have. It can cause segfaults. Your configuration can cause segfaults. Your configuration can cause segfaults. Your configuration can cause segfaults.
And yes, I acknowledged that they can't remove it because it's too late, using those exact words. That doesn't mean it's not a problem. It means you should jump ship to something saner, like lighttpd, which also doesn't have the rewrite-sometimes-redirects problem.
MY configuration never causes segfaults, because I understand the declarative nature of the configuration language, and I don't mistakenly attempt to shoehorn imperative constructs into it.
By your logic, software should not be written in C/C++, because it can cause segfaults!
> It means you should jump ship to something saner, like lighttpd,
Ah, you're a lighttpd guy. I'll stick with not having the http server also be an application server, and we'll agree to disagree.
Have a nice day.
Configuration should not be able to cause your software to segfault. Configuration shouldn't be software. And, in case it's not clear, configuration should not be written in C/C++.
I think I also had to install aptitude on this box (ub 12.04) as it only came with apt-get installed - apt-get is more universal.
Edit: Hrm. 'aptitude' is not the tool of choice for dist-upgrading Debian. I was fresh-installing my debian laptop last year from testing to sid and it was failing to work properly. Hunting down the issue online, it turns out that for dist-upgrades, you just use apt-get. One of those domain-knowledge gotchas :/ Used apt-get, and it went flawlessly.
It is easy to configure Nginx to check if the cached version of the requested URL exists and serve it. But i would like to know if the configuration can be extended bit further to serve the cached file only if is less than a few days old?
http://www.amazon.com/Mastering-Nginx-Dimitri-Aivaliotis/dp/...
https://github.com/NancyFx/Nancy/wiki/Hosting-Nancy-with-Ngi...
it worked perfectly for me on digitalocean
I have literally never heard anyone call it that.
Look here: http://wiki.nginx.org/Pronunciation
Not the most elegant, but it rolls of the tongue relatively well and nobody who was familiar with nginx has ever been confused.
While we're picking nits, I thought this might be worth mentioning:
> The default port for the internet is 80
I'd change that to:
> The default port for the web is 80
Again, wonderful guide!