How to Configure NGINX in CentOS/RHEL

Share It!

NGINX Plus is a high performance web server and proxy server. Nginx doesn’t relay on threads to handle requests. The Nginx also read data from disk and load it into the cache and expire it.

PHP-FPM is a php module. It’s known as FastCGI Process Manager. The PHP-FPM is usually used to allow Nginx to process PHP files.


Step 1: First install below repository on server.

CentOS/RHEL 6, 32 Bit (i686):
# rpm -Uvh

CentOS/RHEL 6, 32 Bit (i386):
# rpm -Uvh

CentOS/RHEL 6, 64 Bit (x86_64):
# rpm -Uvh

CentOS/RHEL 6, 64 Bit x86_64):
# rpm -Uvh

Step 2: Use following command to install Nginx and php-fpm packages:

# yum install nginx –enablerepo=remi
# yum install php-fpm –enablerepo=remi

Step 3: After install the ngnix and php-fpm packages need to change user and group using php-fpm configuration file:

# vim /etc/php-fpm.d/www.conf
Default entry in configuration file:
User = apache
Group = apache
Change entry as below:
User = nginx
Group = nginx

Step 4: Nginx provides default virtual host file, which we can use as a template to create new virtual host files for other domains.

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/

Copy below code and save the file:

server {
        listen 80;
        root   /usr/local/apache2;
        index index.php index.html;
        location / {
        	     try_files $uri $uri/ @handler;
        location @handler {
            	fastcgi_param SCRIPT_FILENAME /usr/local/apache2/index.php;
                include /etc/nginx/fastcgi_params;
                fastcgi_param SCRIPT_NAME /index.php;
   	location ~ .php$ {
               	try_files $uri @handler;
               	fastcgi_index   index.php;
                fastcgi_param SCRIPT_FILENAME /usr/local/apache2$fastcgi_script_name;
                include fastcgi_params;

Step 5: After creating virtual host configuration file we need to start nginx and php-fpm service using following command.

# /etc/init.d/nginx start
# /etc/init.d/php-fpm start

and also enable auto start on system reboot.

# chkconfig ngnix on
# chkconfig php-fpm on

Some other information related with Nginx:

  • Default document Root of Nginx webserver is below:
  • /usr/share/nginx/html
  • Nginx configuration file:
  • /etc/nginx/nginx.conf
  • Php-fpm configuration file:
  • /etc/php-fpm.conf
  • Default nginx virtual host file:
  • /etc/nginx/conf.d/default.conf
  • Default nginx access and error log file:
  • /var/log/nginx/access.log

    Leave a Reply

    Your email address will not be published.