首先, 看这里: http://nginx.org/en/linux_packages.html#stable
第一步: 在/etc/yum.repos.d/下创建nginx.repo文件
第二步: 编辑nginx.repo文件, 内容如下:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
第三步: 安装nginx
yum install nginx
第四步: 编辑nginx.conf
vim /etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php 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 /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$ {
# root html;
root /usr/share/nginx/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;
#}
}
第五步: 启动php-fpm(你可以将它理解为PHP的解释器)
service php-fpm start
[root@proxyin php-fpm.d]# ps -ef | grep php-fpm
root 9707 1 0 03:41 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
apache 9708 9707 0 03:41 ? 00:00:00 php-fpm: pool www
apache 9709 9707 0 03:41 ? 00:00:00 php-fpm: pool www
apache 9710 9707 0 03:41 ? 00:00:00 php-fpm: pool www
apache 9711 9707 0 03:41 ? 00:00:00 php-fpm: pool www
apache 9712 9707 0 03:41 ? 00:00:00 php-fpm: pool www
root 9715 7933 0 03:41 pts/3 00:00:00 grep php-fpm