Nginx做为前端服务器(本机IP:192.168.136.104),将访问PHP页面的动态请求转发给Apache服务器(只监听本地回环地址172.0.0.1:80)
-
安装Apache
# yum -y install httpd -
修改Apache默认端口为81
# vi /etc/httpd/conf/httpd.conf
找到"Listen 80"这行,改为 Listen 127.0.0.1:80 -
安装PHP
# yum -y install php -
安装PHP扩展组件(可选)
# yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash -
设置Apache服务开机自启动
# systemctl enable httpd -
启动Apache服务
# systemctl start httpd -
添加Nginx源
# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# rpm -Uvh nginx-release-centos-7-0.el7.ngx.noarch.rpm -
安装Nginx
# yum install nginx -
修改Nginx配置文件
# vi /etc/nginx/conf.d/default.conflisten 192.168.136.104:;
server_name localhost;
root /var/www/html;
index index.html index.htm index.php;删除location / { ... }节点
取消以下注释:location ~ \.php$ {
proxy_pass http://127.0.0.1;
} -
设置Nginx服务开机自启动
# systemctl enable ngnix -
启动Nginx服务
# systemctl start nginx -
开通防火墙
# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload -
创建测试页面
# vi /var/www/html/index.php<?php phpinfo(); ?>
-
测试站点
浏览http://192.168.136.104