1、下载

# 切换到yum源目录
cd /etc/yum.repos.d

# 下载nginx yum源
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

2、安装

# 安装,得到yum源文件nginx.repo
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

# 查看安装包
yum list | grep nginx

# 显示结果
nginx-release-centos.noarch 6-0.el6.ngx installed
nginx.x86_64 1.16.0-1.el6.ngx nginx
nginx-debug.x86_64 1.8.0-1.el6.ngx nginx
nginx-debuginfo.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-geoip.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-geoip-debuginfo.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-image-filter.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-image-filter-debuginfo.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-njs.x86_64 1.16.0.0.3.2-1.el6.ngx nginx
nginx-module-njs-debuginfo.x86_64 1.16.0.0.3.2-1.el6.ngx nginx
nginx-module-perl.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-perl-debuginfo.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-xslt.x86_64 1.16.0-1.el6.ngx nginx
nginx-module-xslt-debuginfo.x86_64 1.16.0-1.el6.ngx nginx
nginx-nr-agent.noarch 2.0.0-12.el6.ngx nginx
pcp-pmda-nginx.x86_64 3.10.9-9.el6 base

# 安装nginx
yum install nginx.x86_64

3、启动

service nginx start

4、nginx配置文件 

# 配置php
vi /etc/nginx/conf.d/default.conf

* $document_root:# 网站的根目录,在server配置中root指令中指定的值 

server {
listen 80; #配置监听端口
server_name localhost; #配置域名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

root /usr/share/nginx/html; #服务默认启动目录
index index.php index.html index.htm; #默认访问文件

#error_page 404 /404.html; # 配置404页面
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; #错误状态码的显示页面,配置后需要重启
location = /50x.html {
root /usr/share/nginx/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$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
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;
#}
}