Install Nginx with HTTPS support on CentOS

Nginx is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx in 2002, with the first public release in 2004. Nginx now hosts nearly 12.18% (22.2M) of all domains worldwide. As Netcraft predicted, Nginx now surpasses Microsoft IIS as the second most popular web server.

Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

Nginx is one of a handful of servers written to address the C10K problem. Unlike traditional servers, Nginx doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load.
Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from Nginx’s high-performance and small memory footprint. Nginx scales in all directions: from the smallest VPS all the way up to clusters of servers.

Nginx powers several high-visibility sites, such as WordPress, Hulu, Github, Ohloh, SourceForge, WhitePages, TorrentReactor, many more!

Note: The ssl certification is self generated. Therefore it is not recommended for commercial websites, though it can be used for personal use such as hosting an administration area

Download Nginx and Install it

cd
wget http://nginx.org/download/nginx-1.0.11.tar.gz
tar -zxvf nginx-1.0.11.tar.gz
cd nginx-1.0.11
./configure  –with-http_ssl_module
make
make install

Now, let us generate a self signed ssl certificate valid for 1 year

cd /usr/local/nginx/conf
openssl genrsa -out server.key 1024
openssl req -new -key server.key -out server.csr -subj “/C=ab/ST=cd/L=ef/CN=ghij”
mv server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Edit nginx configuration

nano /usr/local/nginx/conf/nginx.conf

Comment out the https section

server {
listen       443;
server_name  localhost;

ssl                  on;
ssl_certificate      server.crt;
ssl_certificate_key  server.key;

ssl_session_timeout  5m;

ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers   on;

location / {
root   html;
index  index.php;
}
}

Now you have to restart nginx to take effect

cd /usr/local/nginx/sbin/
./nginx -s stop
./nginx

Now you can browser https://(your server IP)

Any Questions? Leave a comment 🙂




January 24, 2012
/
Previous Post Next Post

Tharun recommends you to read these fantastic articles