标签 nginx 下的文章

Nginx配置个性二级域名

最近需要配置下个性化二级域名.
效果:
访问的URL http://custom.insoz.com
实际的URL http://www.insoz.com/auth/custom

我们的做法就是通过服务器配置,将访问的url转换为实际的url

下面我们来用nginx配置。配置如下:

server {
        listen       80;
        server_name  *.insoz.com;
        if ( $host ~* (\b(?!www\b)\w+)\.\w+\.\w+ ) {
            set $subdomain $1;
        }
        location / {
            rewrite ^/$ /auth/$subdomain last;
            proxy_pass http://www.insoz.com/;
        }
    }

其中的if,是用于过滤某些特殊的二级域名,比如www,然后获取二级域名的变量值。

rewrite转化为对应的目录

rewrite ^/$ /auth/$subdomain last;

再加上nginx的反向代理功能:

proxy_pass http://www.insoz.com/;

就可以实现了。

这样配置之后,除了if中过滤的二级域名,其他的二级域名{sudomain}.insoz.com,对于服务器,其真实的路径都是www.insoz.com/auth/{sudomain}。

如果url有多种路径规则,则需要一一进行配置。

apache,nginx,php隐藏版本号

当黑客入侵一台服务器时,首先会”踩点”, 这里的”踩点”,指的是了解服务器中运行的一些服务的详细情况,比如说:版本号,当黑客知道相应服务的版本号后,就可以寻找该服务相应版本的一些漏洞来入侵,攻击,所以我们需要隐藏这些版本号来避免一些不必要的问题

我们来测试一下

insoz:~ insoz$ curl -I http://127.0.0.1/phpinfo.php
HTTP/1.1 200 OK
Server: nginx/1.5.0
Date: Thu, 18 Jun 2015 02:39:32 GMT
Content-Type: text/html
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.3.1

可以看到我们的服务器nginx和php版本都暴露了. 下面我们来看隐藏的方法

首先来看nginx中隐藏版本号的方法:
在nginx配置文件nginx.conf中,加入以下代码

server_tokens off;

apache中隐藏版本号的方法:
在apache配置文件httpd.conf中,加入以下代码

ServerTokens Prod
ServerSignature Off

再来看php中隐藏版本号的方法:
在php配置文件php.ini中,加入以下代码

expose_php = Off

好了,修改完毕重启服务,我们再来测试一下:

insoz:~ insoz$ curl -I http://127.0.0.1//phpinfo.php
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 18 Jun 2015 02:41:47 GMT
Content-Type: text/html
Connection: keep-alive
Vary: Accept-Encoding

nginx 各种网站程序Rewrite(伪静态)

Rewrite(伪静态规则)。

#Discuz 7.2 Nginx伪静态

rewrite ^/archiver/((fid|tid)-[w-]+.html)$   /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+).html$   /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
rewrite ^/profile-(username|uid)-(.+).html$ /viewpro.php?$1=$2 last;
rewrite ^/space-(username|uid)-(.+).html$   /space.php?$1=$2 last;
rewrite ^/tag-(.+).html$ /tag.php?name=$1 last;break;

WordPress:

location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

 

PHPCMS:

location / {
###以下为PHPCMS 伪静态化rewrite规则
rewrite ^(.*)show-([0-9]+)-([0-9]+).html$ $1/show.php?itemid=$2&page=$3;
rewrite ^(.*)list-([0-9]+)-([0-9]+).html$ $1/list.php?catid=$2&page=$3;
rewrite ^(.*)show-([0-9]+).html$ $1/show.php?specialid=$2;

####以下为PHPWind 伪静态化rewrite规则
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;
rewrite ^(.*)/simple/([a-z0-9_]+.html)$ $1/simple/index.php?$2 last;
}

 

ECSHOP:

if (!-e $request_filename)
{
rewrite "^/index.html" /index.php last;
rewrite "^/category$" /index.php last;
rewrite "^/feed-c([0-9]+).xml$” /feed.php?cat=$1 last;
rewrite “^/feed-b([0-9]+).xml$” /feed.php?brand=$1 last;
rewrite “^/feed.xml$” /feed.php last;
rewrite “^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-

([a-zA-Z]+)(.*).html$” /category.php?

id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;
rewrite “^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*).html$”

/category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
rewrite “^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*).html$”

/category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
rewrite “^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*).html$” /category.php?

id=$1&brand=$2&page=$3 last;
rewrite “^/category-([0-9]+)-b([0-9]+)(.*).html$” /category.php?id=$1&brand=$2 last;
rewrite “^/category-([0-9]+)(.*).html$” /category.php?id=$1 last;
rewrite “^/goods-([0-9]+)(.*).html” /goods.php?id=$1 last;
rewrite “^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*).html$” /article_cat.php?

id=$1&page=$2&sort=$3&order=$4 last;
rewrite “^/article_cat-([0-9]+)-([0-9]+)(.*).html$” /article_cat.php?id=$1&page=$2 last;
rewrite “^/article_cat-([0-9]+)(.*).html$” /article_cat.php?id=$1 last;
rewrite “^/article-([0-9]+)(.*).html$” /article.php?id=$1 last;
rewrite “^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+).html” /brand.php?

id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
rewrite “^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*).html” /brand.php?id=$1&cat=$2&page=$3

last;
rewrite “^/brand-([0-9]+)-c([0-9]+)(.*).html” /brand.php?id=$1&cat=$2 last;
rewrite “^/brand-([0-9]+)(.*).html” /brand.php?id=$1 last;
rewrite “^/tag-(.*).html” /search.php?keywords=$1 last;
rewrite “^/snatch-([0-9]+).html$” /snatch.php?id=$1 last;
rewrite “^/group_buy-([0-9]+).html$” /group_buy.php?act=view&id=$1 last;
rewrite “^/auction-([0-9]+).html$” /auction.php?act=view&id=$1 last;
rewrite “^/exchange-id([0-9]+)(.*).html$” /exchange.php?id=$1&act=view last;
rewrite “^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*).html$

” /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*).html$” /exchange.php?

cat_id=$1&page=$2&sort=$3&order=$4 last;
rewrite “^/exchange-([0-9]+)-([0-9]+)(.*).html$” /exchange.php?cat_id=$1&page=$2 last;
rewrite “^/exchange-([0-9]+)(.*).html$” /exchange.php?cat_id=$1 last;
}

 

SHOPEX:

location / {
if (!-e $request_filename) {
rewrite ^/(.+.(html|xml|json|htm|php|jsp|asp|shtml))$ /index.php?$1 last;
}
}

 

SaBlog 2.0:

# 只带月份的归档
rewrite "^/date/([0-9]{6})/?([0-9]+)?/?$" /index.php?action=article&setdate=$1&page=$2 last;
# 无分类翻页
rewrite ^/page/([0-9]+)?/?$ /index.php?action=article&page=$1 last;
# 分类
rewrite ^/category/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&cid=$1&page=$2 last;
rewrite ^/category/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&curl=$1&page=$2 last;
# 归档、高级搜索
rewrite ^/(archives|search|article|links)/?$ /index.php?action=$1 last;
# 全部评论、标签列表、引用列表 带分页
rewrite ^/(comments|tagslist|trackbacks|article)/?([0-9]+)?/?$ /index.php?action=$1&page=$2 last;
# tags
rewrite ^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&item=$1&page=$2 last;
# 文章
rewrite ^/archives/([0-9]+)/?([0-9]+)?/?$ /index.php?action=show&id=$1&page=$2 last;
# RSS rewrite ^/rss/([0-9]+)?/?$ /rss.php?cid=$1 last;
rewrite ^/rss/([^/]+)/?$ /rss.php?url=$1 last;
# 用户 rewrite ^/uid/([0-9]+)/?([0-9]+)?/?$ /index.php?action=article&uid=$1&page=$2 last;
rewrite ^/user/([^/]+)/?([0-9]+)?/?$ /index.php?action=article&user=$1&page=$2 last;
# 地图文件
rewrite sitemap.xml sitemap.php last;
# 自定义链接
rewrite ^(.*)/([0-9a-zA-Z-_]+)/?([0-9]+)?/?$ $1/index.php?action=show&alias=$2&page=$3 last;

 

Discuz 7:

rewrite ^/archiver/((fid|tid)-[w-]+.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+).html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+).html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+).html$ /tag.php?name=$1 last;

 

Typecho:

location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

 

modoer:

 

location / {
#index
rewrite ^(.*)/index.html$ $1/index.php last;
#shop comment
rewrite ^(.*)/shop/cate_([0-9]+)_order_([a-z0-9]+)_type_([a-z0-9]+)_offset_([0-9]+).html $1/shop/cate.php?cd=$2&order=$3&ty
pe=$4&offset=$5 last;
rewrite ^(.*)/shop/cate_([0-9]+)_areacode_([0-9]+)_order_([a-z0-9]+)_type_([a-z0-9]+)_offset_([0-9]+).html $1/shop/cate.php
?cd=$2&areacode=$3&order=$4&type=$5&offset=$6 last;
rewrite ^(.*)/shop/cate_([0-9]+)_areacode_([0-9]*)_streetcode_([0-9]*)_order_([a-z0-9]+)_type_([a-z0-9]+)_offset_([0-9]+).h
tml $1/shop/cate.php?cd=$2&areacode=$3&streetcode=$4&order=$5&type=$6&offset=$7 last;
rewrite ^(.*)/shop/cate_([0-9]+)_([a-z0-9]+)_([0-9]+).html $1/shop/cate.php?cd=$2&order=$3&page=$4 last;
rewrite ^(.*)/shop/cate_([0-9]+).html $1/shop/cate.php?cd=$2 last;
rewrite ^(.*)/shop/(shop_|)([0-9]+).html$ $1/shop/shop.php?shopid=$3 last;
rewrite ^(.*)/shop/(shop_|)([0-9]+)$ $1/shop/shop.php?shopid=$3 last;
rewrite ^(.*)/shop/viewreview_([0-9]+).html#respond$ $1/shop/viewreview.php?reviewid=$2#respond last;
rewrite ^(.*)/shop/viewreview_([0-9]+).html$ $1/shop/viewreview.php?reviewid=$2 last;
rewrite ^(.*)/shop/search.html$ $1/shop/search.php last;
rewrite ^(.*)/shop/search_([0-9]+).html$ $1/shop/search.php?searchid=$2&searchsubmit=yes last;
rewrite ^(.*)/shop/rss.xml$ $1/shop/rss.php last;
rewrite ^(.*)/shop/rss_cd_([0-9]+).xml$ $1/shop/rss.php?cd=$2 last;
rewrite ^(.*)/shop/top_pcd_([0-9]+).html$ $1/shop/top.php?pcd=$2 last;
rewrite ^(.*)/shop/top_pcd_([0-9]+)_sort_([a-z0-9]+).html$ $1/shop/top.php?pcd=$2&sort=$3 last;
rewrite ^(.*)/shop/reviews.html$ $1/shop/reviews.php last;
rewrite ^(.*)/shop/reviews_pcd_([0-9]+).html$ $1/shop/reviews.php?pcd=$2 last;
rewrite ^(.*)/shop/reviews_pcd_([0-9]+)_order_([a-z0-9]+)_day_([0-9]+).html$ $1/shop/reviews.php?pcd=$2&order=$3&day=$4 last
;
rewrite ^(.*)/shop/allpic_pcd_([0-9]+).html$ $1/shop/allpic.php?pcd=$2 last;
rewrite ^(.*)/shop/allpic.html$ $1/shop/allpic.php last;
rewrite ^(.*)/shop/tag_(.+).html$ $1/shop/tag.php?tagname=$2 last;
rewrite ^(.*)/shop/tag.html $1/shop/tag.php last;
#person space
rewrite ^(.*)/space/([0-9]+)_([a-z]+)(.html|)$ $1/space/index.php?suid=$2&n=$3 last;
rewrite ^(.*)/space/([0-9]+)(.html|)$ $1/space/index.php?suid=$2 last;
#cash center
rewrite ^(.*)/exchange/index.html$ $1/exchange/index.php last;
rewrite ^(.*)/exchange/gift_([0-9]+).html$ $1/exchange/index.php?action=gift&giftid=$2 last;
#Discount Card
rewrite ^(.*)/coupon/index.html$ $1/coupon/index.php last;
rewrite ^(.*)/coupon/([0-9]+).html$ $1/coupon/index.php?ac=detail&couponid=$2 last;
rewrite ^(.*)/coupon/order_([a-z]+).html$ $1/coupon/index.php?order=$2 last;
rewrite ^(.*)/coupon/pcd_([0-9]*)_order_([a-z]+).html$ $1/coupon/index.php?pcd=$2&order=$3 last;
#news
rewrite ^(.*)/article/([0-9]+).html$ $1/article/article.php?articleid=$2 last;
rewrite ^(.*)/article/classid_([0-9]+)_order_([a-z]+).html$ $1/article/index.php?classid=$2&order=$3 last;
rewrite ^(.*)/article/classid_([0-9]+).html$ $1/article/index.php?classid=$2 last;
rewrite ^(.*)/article/list_shopid_([0-9]+).html $1/article/list.php?shopid=$2 last;
rewrite ^(.*)/article/index.html$ $1/article/index.php last;
#member card
rewrite ^(.*)/card/index.html$ $1/card/index.php last;
rewrite ^(.*)/card/pcd_([0-9]+).html$ $1/card/index.php?pcd=$2 last;
}

 

 

Nginx安装配置

Nginx作为一个后起之秀,他的迷人之处已经让很多人都投入了他的怀抱。配置简单,实现原理简单。做一个负载平衡的再好不过了。

其原理:

简单介绍一下他的安装及配置过程

官方网站
http://wiki.codemongers.com/Main

一、依赖的程序

1. gzip module requires zlib library
2. rewrite module requires pcre library
3. ssl support requires openssl library

二、安装
./configure
make
make install

默认安装的路径是/usr/local/nginx

更多的安装配置
./configure –prefix=/usr/local/nginx
–with-openssl=/usr/include (启用ssl)
–with-pcre=/usr/include/pcre/ (启用正规表达式)
–with-http_stub_status_module (安装可以查看nginx状态的程序)
–with-http_memcached_module (启用memcache缓存)
–with-http_rewrite_module (启用支持url重写)

三、启动及重启

启动:nginx
重启:kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
测试配置文件:nginx -t

简单吧,安装,启动都比较方便。

四、配置文件
http://wiki.codemongers.com/NginxFullExample

#运行用户
user  nobody nobody;
#启动进程
worker_processes  5;
#全局错误日志及PID文件
error_log  logs/error.log notice;
pid        logs/nginx.pid;
#工作模式及连接数上限
events {
  #工作模式有:select(标准模式),poll(标准模式),kqueue(高效模式,适用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),
  #epoll(高效模式,本例用的。适用Linux 2.6+,SuSE 8.2,),/dev/poll(高效模式,适用Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+)
  use epoll;
  worker_connections      1024;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
  #设定mime类型
  include      conf/mime.types;
  default_type  application/octet-stream;
  #设定日志格式
  log_format main        '$remote_addr - $remote_user [$time_local] '
                         '"$request" $status $bytes_sent '
                         '"$http_referer" "$http_user_agent" '
                         '"$gzip_ratio"';
  log_format download    '$remote_addr - $remote_user [$time_local] '
                         '"$request" $status $bytes_sent '
                         '"$http_referer" "$http_user_agent" '
                         '"$http_range" "$sent_http_content_range"';
  #设定请求缓冲
  client_header_buffer_size    10k;
  large_client_header_buffers  4 4k;
  
  #开启gzip模块,要求安装gzip 在运行./config时要指定
  gzip on;
  gzip_min_length  1100;
  gzip_buffers    4 8k;
  gzip_types      text/plain;
  output_buffers  1 32k;
  postpone_output  1460;
  
  #设定访问日志
  access_log  logs/access.log  main;
  client_header_timeout  3m;
  client_body_timeout    3m;
  send_timeout          3m;
  sendfile                on;
  tcp_nopush              on;
  tcp_nodelay            on;
  keepalive_timeout  65;
  
  #设定负载均衡的服务器列表
  upstream backserver {
  #weigth参数表示权值,权值越高被分配到的几率越大
  #本例是指在同一台服务器,多台服务器改变ip即可
  server 127.0.0.1:8081 weight=5;
  server 127.0.0.1:8082;
  server 127.0.0.1:8083;
  }
  #设定虚拟主机,默认为监听80端口,改成其他端口会出现问题
  server {
    listen         80;
    server_name    test.com www.test.com;
    charset utf8;
    #设定本虚拟主机的访问日志
    access_log  logs/test.com.log  main;
    #如果访问 /images/*, /js/*, /css/* 资源,则直接取本地文件,不用转发。但如果文件较多效果不是太好。
    location ~ ^/(images|js|css)/  {
        root    /usr/local/testweb;
        expires 30m;
    }
    
    #对 "/" 启用负载均衡
    location / {
       proxy_pass      http://backserver;
       proxy_redirect          off;
       proxy_set_header        Host $host;
       proxy_set_header        X-Real-IP $remote_addr;
       proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       client_max_body_size    10m;
       client_body_buffer_size 128k;
       proxy_connect_timeout  90;
       proxy_send_timeout      90;
       proxy_read_timeout      90;
       proxy_buffer_size      4k;
       proxy_buffers          4 32k;
       proxy_busy_buffers_size 64k;
       proxy_temp_file_write_size 64k;
    }
    #设定查看Nginx状态的地址,在运行./config 要指定,默认是不安装的。
    location /NginxStatus {
       stub_status            on;
       access_log              on;
       auth_basic              "NginxStatus";
       #是否要通过用户名和密码访问,测试时可以不加上。conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可       
       #auth_basic_user_file  conf/htpasswd;
    }
}

                

yum 安装nginx

 一、更改yum源为网易的源加快速度

vi /etc/yum.repos.d/CentOS-Base.repo
更改内容如下

# CentOS-Base.repo 
# 
# This file uses a new mirrorlist system developed by Lance Davis for CentOS. 
# The mirror system uses the connecting IP address of the client and the 


# update status of each mirror to pick mirrors that are updated to and 
# geographically close to the client. You should use this for CentOS updates 
# unless you are manually picking other mirrors. 
# 
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead. 
# 
# 

[base] 
name=CentOS-$releasever - Base 
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os 
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ 
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ 
gpgcheck=1 
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 

#released updates 
[updates] 
name=CentOS-$releasever - Updates 
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates 
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ 
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/ 
gpgcheck=1 
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 

#packages used/produced in the build but not released 
[addons] 
name=CentOS-$releasever - Addons 
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons 
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/ 
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/ 
gpgcheck=1 
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 

#additional packages that may be useful 
[extras] 
name=CentOS-$releasever - Extras 
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras 
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ 
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/ 
gpgcheck=1 
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 

#additional packages that extend functionality of existing packages 
[centosplus] 
name=CentOS-$releasever - Plus 
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus 
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ 
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/ 
gpgcheck=1 
enabled=0 
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5


二、update yum

yum -y update

三、利用CentOS Linux系统自带的yum命令安装、升级所需的程序库

LANG=C 
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

四、安装php和mysql

yum -y install php mysql mysql-server mysql-devel php-mysql php-cgi php-mbstring php-gd php-fastcgi

五、安装nginx
由于centos没有默认的nginx软件包,需要启用REHL的附件包

rpm -Uvh http://download.Fedora.RedHat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm 
yum -y install nginx

设置开机启动

chkconfig nginx on

六、安装spawn-fcgi来运行php-cgi


yum install spawn-fcgi

七、下载spawn-fcgi 的启动脚本

wget http://bash.cyberciti.biz/dl/419.sh.zip 
unzip 419.sh.zip 
mv 419.sh /etc/init.d/php_cgi 
chmod +x /etc/init.d/php_cgi

启动php_cgi

/etc/init.d/php_cgi start

查看进程

netstat -tulpn | grep :9000

若出现如下代表一切正常

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4352/php-cgi

八、配置nginx(详细配置见nginx.conf详细说明)

location ~ .php$ { 
root html; 
fastcgi_pass 127.0.0.1:9000; 
fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; 
include fastcgi_params; 
}

九、查看phpinfo
编写脚本

phpinfo();

十、安装phpmyadmin
修改/var/lib/php/session的权限和nginx和php_cgi一致

chown -R www.www /var/lib/php/session