How to install nginx web server on CentOS or Debian
How to install nginx web server on CentOS or Debian
Nginx is one of the best web servers available on the internet, Cloudflare is using it to power up all their CDN servers, caching it, compressing data and speeding your website. For those who do not know, it can be used as a standalone server or together with another web server, like apache, as a reverse proxy configuration. Cloudflare for example is using Nginx as a reverse proxy configuration, with gzip active. In this article I’m going to show you real quick how you can install Nginx web server on CentOS or Debian.
Required repositories
From documentation we know that Nginx is available for CentOS 5 and CentOS 6 by default, as well as for Debian Wheezy or Squeeze, so basically we should be good to go if using the latest or previous version of your distribution.
Else you probably want to use Epel repository or directly from Nginx:
1 2 3 4 5 |
### CentOS 5 http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm ### CentOS 6 http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm |
as for Debian, you can use:
1 2 3 |
### codename is the version of debian you are using, eg. wheeze deb http://nginx.org/packages/debian/ codename nginx deb-src http://nginx.org/packages/debian/ codename nginx |
Install nginx on your system
To install nginx is really easy, based on the operating system, you use yum or apt to install the package.
- CentOS
1 |
yum install nginx |
- Debian
1 |
apt-get install nginx |
After you’ve completed the installation you will have the following file configuration created by default:
1 2 3 4 5 6 7 8 9 |
Default configuration directory: /etc/nginx/ Default SSL and vhost config directory (CentOS): /etc/nginx/conf.d/ Default SSL and vhost config directory (Debian): /etc/nginx/sites-available/ Default SSL and vhost config directory (Debian): /etc/nginx/sites-enabled/ Default log file directory: /var/log/nginx/ Default document root directory: /usr/share/nginx/html Default configuration file: /etc/nginx/nginx.conf Default server access log file: /var/log/nginx/access.log Default server access log file: /var/log/nginx/error.log |
The Nginx webserver can be controlled using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
### Starting service service nginx start ### Stopping service service nginx stop ### Restarting service service nginx restart ### Service status service nginx status ### Reload configuration service nginx reload |
So for now, let’s just start the service using the start command:
1 |
service nginx start |
Then using your server IP, try loading it in your browser. Make sure port 80 is open and you should see a similar page like below:
Pages: 1 2