CentOS下用Yum安裝Nginx1.0.9

最近配置了CentOS下用Yum安裝Nginx1.0.9,過程很是有點艱難,花費兩天時間,終於配置成功。特總結如下,希望能給您一點小小的幫助。

首先,對系統進行更新

 
Yum update

 

更新完成後在安裝必要的Gcc

Yum -y install gcc*

完成後,開始進入正式的安裝

 

安裝Mysql

Yum -y install mysql

Yum -y install mysql-server

Service mysqld start

Chkconfig mysqld on

設置Mysql密碼及相關設置就不一一表述了,網上有很多

 

Centos Yum安裝Php-fpm是不支持的,需要導入軟件庫

Centos 5 32

Centos 5 64

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

 

做好這些工作後,我們就可以安裝Nginx了,在安裝前,我們需要添加一個Nginx源,否則Yum安裝不了Nginx.我是從http://wiki.nginx.org/Install上直接複製過來的。

Centos 5

[nginx]

name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

 

OK,萬事俱備了,我們開始Yum安裝了。

Yum -y install nginx

Service nginx start

Chkconfig nginx on

 

安裝Php及相關模塊

Yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy

 

編輯文件php.ini,在文件末尾添加cgi.fix_pathinfo = 1

Vi /etc/php.ini

 

啓動php-fpm

Service php-fpm start

Chkconfig php-fpm on

 

修改Nginx配置文件,添加fastcgi支持

Vi /etc/nginx/nginx.conf

 
user  nginx;

worker_processes  10;

worker_rlimit_nofile 100000;

error_log   /var/log/nginx/error.log;

#error_log  /var/log/nginx/error.log  notice;

#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;

    use epoll;

}

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;

    tcp_nodelay     on;

    server_tokens   off;

    gzip            on;

    gzip_static     on;

    gzip_comp_level 5;

    gzip_min_length 1024;

    keepalive_timeout  65;

    limit_zone   chenwd  $binary_remote_addr  10m;

    # Load config files from the /etc/nginx/conf.d directory

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

    server {

        limit_conn   chenwd  10;

        listen       80;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   /var/www/html;

            index  index.html index.htm index.php;

        }

        error_page  404              /404.html;

        location = /404.html {

            root   /var/www/html;

        }

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   /var/www/html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           /var/www/html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

           #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        location ~ /\.ht {

            deny  all;

        }

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen       443;

    #    server_name  localhost;

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.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.html index.htm;

    #    }

    #}

}

 

重啓Nginx Php-fpm

Service nginx restart

Service php-fpm restart

 

建站info.php文件

Vi /var/www/html/index.php

 

添加如下代碼

<?php

Phpinfo();

?>

 

在瀏覽器打開測試是否正常,如http://域名/index.php

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章