Wednesday, February 9, 2011

How to : install and config Nginx/PhP fastcgi on Centos

To Install Nginx, setup the prerequisites as following.

yum install GCC #C compiler
yum install pcre* # perl regular expression
yum install zlib zlib-devel
yum install openssl openssl-devel

Download Nginx From http://nginx.org/en/download.html, and extract to a source folder, I will use /tmp here

wget http://nginx.org/download/nginx-0.8.54.tar.gz
tar
-zxvf nginx-0.8.54.tar.gz
cd /tmp/nginx-0.8.54

./configure  --prefix=/opt/nginx
make && make install

once done, you can run ./nginx –? to show all available options ,

image

for the default loading, it read the conf file which is  conf/nginx.conf 
 
to start the nginx, just run ./nginx, you will get the helloworld page.

image

here, I changed ngingx.conf a little with a New port 88, and basic proxy forward to Apache,PHP (check installation instructions, Install PHP to Apache web server)

server {
        listen       88;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
       location ~ \.php$ {
            proxy_pass  
http://127.0.0.1;
        }


if I access http://localhost:88/info.php, nginx will forward the request to http://localhost/info.php
image

But the server header is nginx Now. Also the ngnix has enabled the GZIP support now. ( a great reverse proxy, offloading those cut-off features)

image


more how-tos:

How to: install apache 2.2 on centos
How To: Install PHP to Apache web server

No comments:

 
Locations of visitors to this page