Nginx is a lightweight web server (HTTP, SMTP, IMAP, POP3 ..). It has very low memory footprints with higher degree of concurrency. It’s a free and open source software, runs on all major OS (Unix, Linux, BSD, Mac OS X, Microsoft Windows and more).
Setup Nginx on Ubuntu (12.04) LTS Server
Nginx is already available in Ubuntu repository, but it’s very outdated (it may be ok for development or testing but not for deployment) so for production environment you should install the newer version – either from the source or PPA.
1. Update
sudo apt-get -y update sudo apt-get -y upgrade
2. Dependencies
For adding ppa you need to install the python-software-properties
package.
sudo apt-get -y install python-software-properties
3. Install nginx
sudo apt-add-repository -y ppa:nginx/stable sudo apt-get -y update sudo apt-get -y install nginx
4. Start the server!
sudo service nginx start
Now, move on to the address (IP address of your VPS or the domain name or the localhost(in case of development environment)). You should see the default page served by nginx.
5. setup server configs
For editing file over the ssh, you can use a command line editor such as Vi or Nano. I recommend nano if you want a text editor without any learning curve.
Install Nano, a lightweight text editor
sudo apt-get -y install nano
Then create a server configuration file for your app/site. (you could also just edit the global config(/etc/nginx/nginx.conf
), it’s fine if you’ve only one app/site running on a virtual private server but if you plan to deploy multiple apps/websites to a single VPS – then you should create seperate configs for each website)
sudo nano /etc/nginx/sites-available/example.com
After creating the config file (if you don’t know how – then read the official tutorials), create a symlink
sudo ln -nfs /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
Now, restart the server!
sudo service nginx restart