Static Website Configuration for Nginx Web Server on CentOS 6 / CentOS 7

Q. How to configure and host static website on Nginx web server?

A. Nginx is a lightweight web server and an alternative to Apache. In order to run a static website on Nginx web server, you must configure your server to at least the following basic configuration. Failure to do this will stop some basic functions such as access to sitemap.xml which is required when submit a page to google and bing in webmaster tool.

Note : The following steps has been tested using root access on Nginx web server :

Static Website Configuration for Nginx Web Server

1. This is main Nginx configuration file. Make sure that sites-available folder was included at the bottom of the configuration as below :

# sudo vim /etc/nginx/nginx.conf
user  nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;


    include /etc/nginx/sites-available/*.conf;
}

2. Create static.conf file which contains the configuration specific for static website that running on Nginx web server :

# sudo vim /etc/nginx/conf.d/static.conf
# WORDPRESS : Rewrite rules, sends everything through index.php and keeps the appended query string intact
location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*.php$ {
    deny all;
}
# REQUIREMENTS : Enable PHP Support
location ~ .php$ {
    # SECURITY : Zero day Exploit Protection
    try_files $uri =404;
    # ENABLE : Enable PHP, listen fpm sock
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    #fastcgi_pass unix:/tmp/php-fpm.sock;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300s;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 4k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;
}

location /sitemap.xml.gz {
    add_header Cache-Control "public, must-revalidate";
}

3. Create common.conf file for common option in Nginx web server :

# sudo vim /etc/nginx/conf.d/common.conf

Add below :

# Global configuration file.
# ESSENTIAL : Configure Nginx Listening Port
listen 80;
# ESSENTIAL : Default file to serve. If the first file isn't found,
index index.php index.html index.htm;
# ESSENTIAL : no favicon logs
location = /favicon.ico {
    log_not_found off;
    access_log off;
}
# ESSENTIAL : robots.txt
location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}
# ESSENTIAL : Configure 404 Pages
error_page 404 /404.html;
# ESSENTIAL : Configure 50x Pages
error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
# SECURITY : Deny all attempts to access hidden files .abcde
location ~ /. {
    deny all;
}
# PERFORMANCE : Set expires headers for static files and turn off logging.
location ~* ^.+.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    access_log off; log_not_found off; expires 30d;
   add_header Pragma no-cache;
   add_header Cache-Control "public";
}

4. Configure website1 configuration :

# sudo vim /etc/nginx/sites-available/website1.com.conf
server {
    listen      80;
    server_name website1.com;
    rewrite ^/(.*)$ http://www.website1.com/$1 permanent;

}

server {
        server_name www.website1.com;
        root /var/www/html/website1.com;
        access_log /var/log/nginx/website1.com.access.log;
        error_log /var/log/nginx/website1.com.error.log;
        include conf.d/common.conf;
        include conf.d/static.conf;

}

5. Verify Nginx configuration syntax :

# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

6. Restart Nginx web server :

For CentOS 7 :

# sudo systemctl restart nginx

For CentOS 5/ CentOS 6

# sudo service nginx restart

static website

Static website are the cheapest was to start a website and does not require a lot of server resources to run it. Basic shared hosting plan is sufficient to use and nowaday static website is widely used by companies that are smaller.

How to Install Lighttpd With PHP5 (PHP-FPM) and MySQL on CentOS 6.5

Lighttpd (pronounced “lighty”) is an open-source web server as an alternative to Apache and Nginx. It is a secure, flexible, fast and designed for speed-critical environments. It has a low memory footprint and can handle large number of connections in one server especially for busier sites.

PHP is an acronym for “PHP Hypertext Preprocessor”; PHP is a widely-used server-side scripting language executed on the server.

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

MySQL is a popular database solution for use in web applications.

This post will show you how to install Lighttpd With PHP5 (PHP-FPM) and MySQL on CentOS 6.5 VPS or dedicated server.

1. EPEL repository is another extra repository that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL) and CentOS server. How to Configure EPEL Repository on CentOS.

2. Install Lighttpd, MySQL and PHP5 work in Lighttpd through PHP-FPM :

[root@centos6-05 ~]# yum install lighttpd php php-fpm lighttpd-fastcgi php-mysql mysql mysql-server -y

3. Configure Lighttpd :

[root@centos6-05 ~]# vi /etc/lighttpd/lighttpd.conf
server.use-ipv6 = "enable"

Change to :

server.use-ipv6 = "disable"

4. Make lighttpd start at boot and also start lighttpd service:

[root@centos6-05 ~]# chkconfig --levels 235 lighttpd on
[root@centos6-05 ~]# /etc/init.d/lighttpd start

Browse your web server and Lighttpd welcome page should be displayed :
lighttpd-centos6.5-1

5. Configure PHP to work in Lighttpd through PHP-FPM :

[root@centos6-05 ~]# vi /etc/php-fpm.d/www.conf

Enable PHP-FPM use a TCP connection instead of unix socket :

;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

Configure user and group to lighttpd :

..
..
; RPM: apache Choosed to be able to access some dir as httpd
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd
..
..

6. Make php-fpm start at boot and also start the php-fpm service :

[root@centos6-05 ~]# chkconfig --levels 235 php-fpm on
[root@centos6-05 ~]# /etc/init.d/php-fpm start

7. Open and modify /etc/php.ini :

[root@centos6-05 ~]# vi /etc/php.ini

Uncomment the line cgi.fix_pathinfo=1

..
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=1
..

8. Open and modify /etc/lighttpd/modules.conf :

[root@centos6-05 ~]# vi /etc/lighttpd/modules.conf

Uncomment the line include “conf.d/fastcgi.conf”:

..
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"
..

9. Open and modify /etc/lighttpd/conf.d/fastcgi.conf :

Add below fastcgi.server at bottom of the file :

..
fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)
..

10. Reload the PHP-FPM and Lighttpd service :

[root@centos6-05 ~]# /etc/init.d/php-fpm reload
[root@centos6-05 ~]# /etc/init.d/lighttpd reload

11. Since MySQl has been install, dont forget to make MySQL start at boot and start the MySQL service :

[root@centos6-05 ~]# chkconfig --levels 235 mysqld on
[root@centos6-05 ~]# /etc/init.d/mysqld start

12. Create info.php under ligghttpd document root :

[root@centos6-05 ~]# vi /var/www/lighttpd/info.php
<?php
phpinfo();
?>

Browse your page http://IP-Adress/info.php. Thats all.

How to Fix “Could not reliably determine the server’s fully qualified domain name”

apache-http-serverQuestion :
How to fix “Could not reliably determine the server’s fully qualified domain name” when starting apache httpd service ?

[root@centos64 ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for centos64.ehowstuff.local
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]

Answer :

Step 1:

Update /etc/hosts and do server’s ip address resolvable to the fully qualified domain name(fqdn) or hostname.

[root@centos64 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.2.62 centos64.ehowstuff.local

Step 2:

Restart apache httpd service :

[root@centos64 ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

How to Setup Nginx With PHP-FastCGI on CentOS 6.2/CentOS 6.3 VPS Server

At the previous post, i have setup Nginx as reverse proxy to apache web server. This post will covers the steps how to setup nginx web server to use PHP-FastCGI for dynamic content. Nginx (pronounced “Engine-X”) is a free, open-source HTTP Web server and one of the alternative to Apache http server. It’s a high performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure. FastCGI is a language independent, scalable, open extension to CGI that provides high performance without the limitations of server specific APIs. FastCGI provides better scalability and performance.

1. Prepared yum repository for nginx :

[root@centos63 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

2. Install Nginx :

[root@centos63 ~]# yum install nginx -y

3. Install required php packages :

[root@centos63 ~]# yum install php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy -y

Examples of Software Installed and the Dependency:

Installed:
  php-eaccelerator.i686 1:0.9.6.1-1.el6   php-imap.i686 0:5.3.3-14.el6_3      php-ldap.i686 0:5.3.3-14.el6_3
  php-magickwand.i686 0:1.0.9-1.el6       php-magpierss.noarch 0:0.72-6.el6   php-mssql.i686 0:5.3.3-1.el6
  php-odbc.i686 0:5.3.3-14.el6_3          php-pear.noarch 1:1.9.4-4.el6       php-shout.i686 0:0.9.2-6.el6
  php-snmp.i686 0:5.3.3-14.el6_3          php-soap.i686 0:5.3.3-14.el6_3      php-tidy.i686 0:5.3.3-14.el6_3
  php-xml.i686 0:5.3.3-14.el6_3           php-xmlrpc.i686 0:5.3.3-14.el6_3

Dependency Installed:
  ConsoleKit.i686 0:0.4.1-3.el6                        ConsoleKit-libs.i686 0:0.4.1-3.el6
  GConf2.i686 0:2.28.0-6.el6                           ImageMagick.i686 0:6.5.4.7-6.el6_2
  ORBit2.i686 0:2.14.17-3.1.el6                        atk.i686 0:1.28.0-2.el6
  avahi-libs.i686 0:0.6.25-11.el6                      cairo.i686 0:1.8.8-3.1.el6
  cups-libs.i686 1:1.4.2-48.el6_3.1                    dbus.i686 1:1.2.24-7.el6_3
  eggdbus.i686 0:0.6-3.el6                             fontconfig.i686 0:2.8.0-3.el6
  freetds.i686 0:0.91-2.el6                            ghostscript.i686 0:8.70-14.el6_3.1
  ghostscript-fonts.noarch 0:5.50-23.1.el6             gtk2.i686 0:2.18.9-10.el6
  hicolor-icon-theme.noarch 0:0.11-1.1.el6             jasper-libs.i686 0:1.900.1-15.el6_1.1
  lcms-libs.i686 0:1.19-1.el6                          libICE.i686 0:1.0.6-1.el6
  libIDL.i686 0:0.8.13-2.1.el6                         libSM.i686 0:1.1.0-7.1.el6
  libXcomposite.i686 0:0.4.1-2.el6                     libXcursor.i686 0:1.1.10-2.el6
  libXdamage.i686 0:1.1.2-1.el6                        libXext.i686 0:1.1-3.el6
  libXfixes.i686 0:4.0.4-1.el6                         libXfont.i686 0:1.4.1-2.el6_1
  libXft.i686 0:2.1.13-4.1.el6                         libXi.i686 0:1.3-3.el6
  libXinerama.i686 0:1.1-1.el6                         libXrandr.i686 0:1.3.0-4.el6
  libXrender.i686 0:0.9.5-1.el6                        libXt.i686 0:1.0.7-1.el6
  libc-client.i686 0:2007e-11.el6                      libcroco.i686 0:0.6.2-5.el6
  libfontenc.i686 0:1.0.5-2.el6                        libgsf.i686 0:1.14.15-5.el6
  libogg.i686 2:1.1.4-2.1.el6                          librsvg2.i686 0:2.26.0-5.el6_1.1.0.1.centos
  libshout.i686 0:2.2.2-5.1.el6                        libthai.i686 0:0.1.12-3.el6
  libtheora.i686 1:1.1.0-2.el6                         libtidy.i686 0:0.99.0-19.20070615.1.el6
  libtiff.i686 0:3.9.4-6.el6_3                         libvorbis.i686 1:1.2.3-4.el6_2.1
  libwmf-lite.i686 0:0.2.8.4-22.el6.centos             lm_sensors-libs.i686 0:3.1.1-10.el6
  net-snmp.i686 1:5.5-41.el6_3.1                       net-snmp-libs.i686 1:5.5-41.el6_3.1
  pango.i686 0:1.28.1-3.el6_0.5.1.centos               pixman.i686 0:0.18.4-1.el6_0.1
  polkit.i686 0:0.96-2.el6_0.1                         sgml-common.noarch 0:0.6.3-32.el6
  speex.i686 0:1.2-0.12.rc1.1.el6                      unixODBC.i686 0:2.2.14-11.el6
  urw-fonts.noarch 0:2.4-10.el6                        xorg-x11-font-utils.i686 1:7.2-11.el6

Dependency Updated:
  dbus-libs.i686 1:1.2.24-7.el6_3

Complete!

4. Configure EPEL Repository on CentOS 6.3 and install spawn-fcgi :

[root@centos63 ~]# yum install spawn-fcgi -y

5. Start configure nginx. It is better to backup original nginx config file :

[root@centos63 ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

6. Create nginx DocumentRoot for ehowstuff.local virtual host :

[root@centos63 ~]# mkdir -p /var/www/html/ehowstuff.local
[root@centos63 ~]# mkdir -p /var/www/html/ehowstuff.local/public_html
[root@centos63 ~]# chown -R nginx:nginx /var/www/html/ehowstuff.local/public_html

7. Create folder where to store access.log and error.log :

[root@centos63 ~]# mkdir -p /var/log/nginx/ehowstuff.local
[root@centos63 ~]# chown -R nginx:nginx /var/log/nginx/ehowstuff.local

8. Modify default nginx config file :

[root@centos63 ~]# vi /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}


9. Add the host configuration file under /etc/nginx/conf.d/. Nginx config file will load all *.conf files under conf.d folder :

As example, the website domain is ehowstuff.local. So virtual server ehowstuff.local will be created and named as ehowstuff.local.conf :

[root@centos63 ~]# vi /etc/nginx/conf.d/ehowstuff.local.conf
server {
    server_name www.ehowstuff.local ehowstuff.local;
    access_log /var/log/nginx/ehowstuff.local/access.log;
    error_log /var/log/nginx/ehowstuff.local/error.log;
    root /var/www/html/ehowstuff.local/public_html;

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

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/html/ehowstuff.local/public_html$fastcgi_script_name;
    }
}

10. Check your nginx version :

[root@centos63 ~]# nginx -v
nginx version: nginx/1.2.4

11. Configure php-fastcgi :

[root@centos63 ~]# cd /opt
[root@centos63 opt]# wget -O php-fastcgi-rpm.sh http://library.linode.com/assets/696-php-fastcgi-rpm.sh
[root@centos63 opt]# mv php-fastcgi-rpm.sh /usr/bin/php-fastcgi
[root@centos63 opt]# chmod +x /usr/bin/php-fastcgi
[root@centos63 opt]# wget -O php-fastcgi-init-rpm.sh http://library.linode.com/assets/697-php-fastcgi-init-rpm.sh
[root@centos63 opt]# mv php-fastcgi-init-rpm.sh /etc/rc.d/init.d/php-fastcgi
[root@centos63 opt]# chmod +x /etc/rc.d/init.d/php-fastcgi

12. Start php-fastcgi to control spawn-fcgi :

[root@centos63 ~]# /etc/init.d/php-fastcgi start
Starting php-cgi: spawn-fcgi: child spawned successfully: PID: 3380
                                                           [  OK  ]

13. Start Nginx service :

[root@centos63 ~]# service nginx start

14. Make Nginx and php-fastcgi start at boot :

[root@centos63 opt]# chkconfig --add nginx
[root@centos63 opt]# chkconfig nginx on
[root@centos63 opt]# chkconfig --add php-fastcgi
[root@centos63 opt]# chkconfig php-fastcgi on

Nginx Reverse Proxy Setup for Linux Server

Nginx Reverse ProxyNginx also pronounced “Engine-X” is a free, open-source HTTP Web server and one of the best alternative to Apache http server. It is a high-performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure. Nginx also provides a combination of Nginx web servers, Nginx reverse proxy and Nginx load balancing solution to the websites that running on high traffic and just wants to be consistently efficient. Nginx has the lowest memory footprint possible and optimizes CPU usage while delivering maximum performance even on a very cheap server hardware. More importantly, Nginx is able to continuously take more connections while maintaining low memory usage.

What is Nginx Reverse Proxy ?

When Nginx reverse proxy received request, it sends a request to the specified proxied server. In this case the specified proxied server is Apache web server. When Nginx reverse proxy fetches the response from Apache web server, It will sends it back to the client. In other words, Nginx reverse proxy serve as front-end server for Apache web service.

How to Setup Nginx Reverse Proxy for Linux

This article will show you how to install and configure Nginx reverse proxy for Apache web server. It was assumed that Apache web server has been running at 192.168.1.55 and nginx will be install at another server with Ip address, 192.168.1.54. This has been tested and working fine at CentOS 6 / CentOS 7 / RHEL 7 / Oracle Linux 7.

Nginx Reverse Proxy Server : 192.168.1.54
Apache Web server : 192.168.1.55

1. Prepared yum repository for nginx :

# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

2. Perform yum install for nginx :

# yum install nginx -y

3. Backup original nginx config file :

# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

4. Modify default nginx config file :

# vi /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {

    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    charset   utf-8;
    keepalive_timeout  65;
    server_tokens       off;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         off;

    server {
          listen 80;
          server_name  _;
          root   /usr/share/nginx/html;
          index  index.html index.htm;     }

    include  conf.d/*.conf;
}

5. Add the host configuration file under /etc/nginx/conf.d/. Nginx config file will load all *.conf files under conf.d folder :

As example, the website domain is ehowstuff.local. So virtual server ehowstuff.local will be created and named as ehowstuff.local.conf :

# vi /etc/nginx/conf.d/ehowstuff.local.conf
server {
      listen 80;
      server_name  ehowstuff.local www.ehowstuff.local;

 access_log  off;
 error_log off;

location / {
  proxy_pass              http://192.168.1.55:80/;
  proxy_set_header        X-Real-IP       $remote_addr;
  proxy_set_header        Host  $host;
  proxy_redirect          off;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_connect_timeout   90;
  proxy_send_timeout      90;
  proxy_read_timeout      90;
  client_max_body_size    10m;
  client_body_buffer_size 128k;
  proxy_buffer_size       4k;
  proxy_buffers           4 32k;
  proxy_busy_buffers_size 64k;
}
}

On above configuration file, all the traffic to ehowstuff.local port 80 will be redirected to the Apache web server that hosted at 192.168.1.55. Nginx reverse proxy serve as front-end server for Apache web service.

6. Verify the configuration file :

# /usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

7. Start nginx server :

# service nginx start

8. Configure nginx start at boot :

# chkconfig nginx on

 

How to Install Nginx Web Server on CentOS 6.3

Nginx or “engine x” is a free, open-source HTTP server and one of the alternative to Apache http server. It’s a high performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure. This post will show the quick step to install nginx on linux CentOS 6.3 server.

1. Prepared yum repository for nginx :

[root@centos63 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

2. Perform yum install for nginx :

[root@centos63 ~]# yum install nginx -y

Examples :

[root@centos63 ~]# yum install nginx -y
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirrors.hostemo.com
 * extras: mirrors.hostemo.com
 * updates: mirrors.hostemo.com
nginx                                                                        | 1.3 kB     00:00
nginx/primary                                                                | 3.9 kB     00:00
nginx                                                                                         25/25
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nginx.i386 0:1.2.2-1.el6.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package              Arch                Version                        Repository            Size
====================================================================================================
Installing:
 nginx                i386                1.2.2-1.el6.ngx                nginx                308 k

Transaction Summary
====================================================================================================
Install       1 Package(s)

Total download size: 308 k
Installed size: 623 k
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 308 k
nginx-1.2.2-1.el6.ngx.i386.rpm                                               | 308 kB     00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : nginx-1.2.2-1.el6.ngx.i386                                                       1/1
----------------------------------------------------------------------

Thanks for using NGINX!

Check out our community web site:
* http://nginx.org/en/support.html

If you have questions about commercial support for NGINX please visit:
* http://www.nginx.com/support.html

----------------------------------------------------------------------
  Verifying  : nginx-1.2.2-1.el6.ngx.i386                                                       1/1

Installed:
  nginx.i386 0:1.2.2-1.el6.ngx

Complete!

3. Start nginx :

[root@centos63 ~]# service nginx start
Starting nginx:                                            [  OK  ]

4. Make nginx auto start at boot :

[root@centos63 ~]# chkconfig nginx on

How to Install and Configure Nginx Web Server on CentOS 6.2

Nginx or “engine x” is a free, open-source HTTP server and one of the alternative to Apache http server. It’s a high performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure. In this post, i will guide you through the basic steps to install and configure Nginx web server on linux CentOS 6.2 server.

To add nginx yum repository, create a file named /etc/yum.repos.d/nginx.repo.

[root@centos62 ~]# vi /etc/yum.repos.d/nginx.repo

Paste one of the configurations below:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Install nginx using yum command :

[root@centos62 ~]# yum install nginx -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * epel: ftp.yz.yamagata-u.ac.jp
 * extras: centos.ipserverone.com
 * rpmforge: apt.sw.be
 * updates: centos.ipserverone.com
nginx                                                                        | 1.3 kB     00:00
nginx/primary                                                                | 3.0 kB     00:00
nginx                                                                                         17/17
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nginx.i686 0:1.0.12-1.el6 will be updated
---> Package nginx.i386 0:1.0.14-1.el6.ngx will be an update
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package             Arch               Version                           Repository           Size
====================================================================================================
Updating:
 nginx               i386               1.0.14-1.el6.ngx                  nginx               294 k

Transaction Summary
====================================================================================================
Upgrade       1 Package(s)

Total download size: 294 k
Downloading Packages:
nginx-1.0.14-1.el6.ngx.i386.rpm                                              | 294 kB     00:43
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : nginx-1.0.14-1.el6.ngx.i386                                                      1/2
  Cleanup    : nginx-1.0.12-1.el6.i686                                                          2/2

Updated:
  nginx.i386 0:1.0.14-1.el6.ngx

Complete!

Modify default website config file :

[root@centos62 ~]# vi /etc/nginx/conf.d/default.conf

Original

 location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

Edit as below :

 location / {
        #root   /usr/share/nginx/html;
        root   /var/www/html/nginxweb;
        index  index.html index.htm;

Create index.html :

[root@centos62 ~]# vi /var/www/html/nginxweb/index.html

Add this html code:

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for nginx web server
</div>
</body>
</html>

Start nginx web server :

[root@centos62 ~]# service nginx start

How to Install and Configure Lighttpd on CentOS 6.2

The Lighttpd is an open-source web server more optimized for speed-critical environments than common products while remaining standards-compliant, secure and flexible. Lighttpd is an excellent tool for small to medium sized web sites. It is a web server for Linux/UNIX and Windows operating systems platform and is an alternative to Apache web server. In this post, i will show on how to setup Lighttpd on linux CentOS 6.2 server.

1. Install and configure PMforge Repository on CentOS 6.2 :
How to Add the RPMforge Repository on CentOS 6/RHEL 6 Linux Server

2. Install lighttpd using yum command :

[root@centos62 ~]# yum install lighttpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * extras: centos.ipserverone.com
 * rpmforge: ftp-stud.fht-esslingen.de
 * updates: centos.ipserverone.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package lighttpd.i686 0:1.4.28-2.el6.rf will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package               Arch              Version                        Repository             Size
====================================================================================================
Installing:
 lighttpd              i686              1.4.28-2.el6.rf                rpmforge              706 k

Transaction Summary
====================================================================================================
Install       1 Package(s)

Total download size: 706 k
Installed size: 2.6 M
Downloading Packages:
lighttpd-1.4.28-2.el6.rf.i686.rpm                                            | 706 kB     00:08
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : lighttpd-1.4.28-2.el6.rf.i686                                                    1/1

Installed:
  lighttpd.i686 0:1.4.28-2.el6.rf

Complete!

3. Configure Lighttpd starts automatically when boot up :

[root@centos62 ~]# chkconfig --levels 235 lighttpd on

or

[root@centos62 ~]# chkconfig lighttpd on

4. Open /etc/lighttpd/lighttpd.conf :

[root@centos62 ~]# vi /etc/lighttpd/lighttpd.conf

Make sure server.use-ipv6 is set to “disable” :

##
## Use IPv6?
##
server.use-ipv6 = "disable"

5. The server.document-root is located at /srv/www/lighttpd. Upload or create the following index.html to test your web server :

[root@centos62 ~]# vi /srv/www/lighttpd/index.html

Add this html code into index.html

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Lighttpd Test Page on CentOS 6.2
</div>
</body>
</html>

6. Start lighttpd :

[root@centos62 ~]# /etc/init.d/lighttpd start
Starting lighttpd:                                         [  OK  ]

7. Browser your server ip address :
http:server_ip_address
Lighttpd

How to Install Apache Httpd Server on RHEL 6

In this post, i will show on how to install Apache Httpd server on Redhat Enterprise Linux 6 (RHEL 6). The Apache HTTP Server is an open-source HTTP server for modern operating systems such as Unix, Linux and windows platform. This post assumed that you have set up local yum repository using your DVDROM. If you haven’t set up the local yum repository, please proceed to this steps :
How to Setup Local Yum Repository from CD-ROM/DVD-ROM image on RHEL 6

Simply run this command to install Apache Httpd server :

    [root@rhel6 ~]# yum install httpd -y
    Loaded plugins: rhnplugin
    This system is not registered with RHN.
    RHN support will be disabled.
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.i686 0:2.2.15-5.el6 set to be updated
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ====================================================================================================
     Package           Arch             Version                  Repository                        Size
    ====================================================================================================
    Installing:
     httpd             i686             2.2.15-5.el6             DVD-RHEL6-Repository             813 k
    
    Transaction Summary
    ====================================================================================================
    Install       1 Package(s)
    Upgrade       0 Package(s)
    
    Total download size: 813 k
    Installed size: 2.8 M
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing     : httpd-2.2.15-5.el6.i686                                                      1/1
    
    Installed:
      httpd.i686 0:2.2.15-5.el6
    
    Complete!
    

Command to start Httpd service :

    [root@rhel6 ~]# service httpd start
    Starting httpd:                                            [  OK  ]
    

Command to stop Httpd service :

    [root@rhel6 ~]# service httpd stop
    Stopping httpd:                                            [  OK  ]
    

Command to restart Httpd service :

    [root@rhel6 ~]# service httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
    

Make Apache Httpd service auto start at boot :

    [root@rhel6 ~]# chkconfig httpd on