前提
已經安裝 LAMP 環境
安裝 nginx:
yum install -y nginx
安裝 php-fpm:
yum install -y php-fpm
啓動php-fpm
# centos 6.x
/etc/init.d/php-fpm start
chkconfig --level 2345 php-fpm on # 開機自啓動
# centos 7.x
systemctl start php-fpm.service
systemctl enable php-fpm.service # 開機自啓動
關閉httpd
# 關閉80端口
# centos 6.x
service httpd stop
systemctl stop httpd.service
# 關閉開機自啓動
# centos 6.x
chkconfig --level 2345 httpd off
# centos 7.x
systemctl disable httpd.service
配置 nginx虛擬主機:
#vi /etc/nginx/conf.d/virtual.conf
server {
listen 80; #監聽端口號
server_name www.nginxtest.com; #主機名稱
access_log /tmp/logs/bbb.entoscn.com_access.log combined;
location / {
index index.php index.html index.htm; #默認首頁文件
root /var/www/html/; #網站目錄
}
location ~ .*\.php$ {
fastcgi_pass 127.0.0.1:9000;# 9000是php-fpm的端口, 可以通過 netstat -tlnp 查看
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; #解析php
include fastcgi_params;#解析php
}
}
nginx 啓動
# centos 6.x
/etc/init.d/nginx start
chkconfig --level 2345 nginx on
# centos 7.x
systemctl start nginx.service
systemctl enable nginx.service