初识动静分离--nginx与LAMP(快速部署)

环境

一台centos7LAMP架构可处理动态页面 20.0.0.110nat模式
一台centos7Nginx服务器主要负责处理静态页面20.0.0.31 nat模式
一台Windows10客户端20.0.0.85 nat模式

配置

LAMP

Apache

[root@localhost ~]#yum -y install httpd httpd-devel

[root@localhost ~]#firewall-cmd --permanent --zone=public --add-service=http
[root@localhost ~]#firewall-cmd --permanent --zone=public --add-service=https

[root@localhost ~]#firewall-cmd --reload

[root@localhost ~]#systemctl start httpd

可以去客户端访问一下20.0.0.110,测试下Apache
在这里插入图片描述

数据库mariadb

[root@localhost ~]#yum -y install mariadb mariadb-server mariadb mariadb-libs mariadb-devel -y

[root@localhost ~]#systemctl start mariadb
[root@localhost ~]#mysql_secure_installation
Enter current password for root (enter for none):      ##回车
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y      ##设置root密码
New password:              ##输入密码
Re-enter new password:           ##再次输入密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n    ##不移除匿名用户
 ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n    ##允许远程登录
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n  ##允许测试数据库和访问它
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y    ##重载数据
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost ~]# 

PHP

[root@localhost ~]# yum -y install php php-mysql 
[root@localhost ~]# yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

[root@localhost ~]# cd /var/www/html
[root@localhost html]# vim index.php
 <?php
phpinfo();
?>
[root@localhost ~]# 

这样LAMP就搭建好了,可以去客户端访问20.0.0.110
在这里插入图片描述

Nginx

安装还是一样安装,可参考nginx部分
修改下配置文件

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
...
 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        location ~ \.php$ {                            ##开启代理模块,将PHP的请求转交给20.0.0.110
            proxy_pass   http://20.0.0.110;
        }

        # pass the PHP scripts t
...
[root@nginx ~]#systemctl start nginx

测试

可以去客户端测试访问20.0.0.31,可看到nginx的页面,你们的应该是没有那种小熊的,因为我是接着上此的做的,之前配置过
在这里插入图片描述
访问20.0.0.31/index.php可看到PHP的页面,这是转交给20.0.0.110处理的页面
在这里插入图片描述
相关工具
相关软件包

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值