- Nginx的静态处理能力很强,但是动态处理能力不足,因此,在企业中常用动静分离技术
- 针对PHP的动静分离
静态页面交给Nginx处理
动态页面交给PHP-FPM模块或Apache处理- 在Nginx的配置中,是通过location配置段配个正则匹配实现静态与动态页面的不同处理方式
LAMP服务器(192.168.13.139) Nginx服务器(192.168.13.140)
[root@lamp ~]# yum install httpd httpd-devel -y ##安装http服务及开发包 [root@lamp ~]# systemctl start httpd.service ##开启服务 [root@lamp ~]# firewall-cmd --permanent --zone=public --add-service=http ##防火墙允许http success [root@lamp ~]# firewall-cmd --permanent --zone=public --add-service=https success [root@lamp ~]# firewall-cmd --reload ##重启防火墙 success
[root@lamp ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y ##安装数据库 [root@lamp ~]# systemctl start mariadb ##开启数据库 [root@lamp ~]# netstat -ntap | grep 3306 ##查看端口号3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2200/mysqld [root@lamp ~]# mysql_secure_installation ##设置数据库 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: ##确认密码 Remove anonymous users? [Y/n] n ##允许匿名访问 ... skipping. Disallow root login remotely? [Y/n] n ##允许远程登录 ... skipping. Remove test database and access to it? [Y/n] n ##保留测试数据库 ... skipping. 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@lamp ~]# yum install php -y ##安装PHP [root@lamp ~]# yum install php-mysql -y ##建立php和mysql关联 [root@lamp ~]# yum install -y \ > php-gd ##GD库是php处理图形的扩展库 > php-ldap ##轻量级目录访问协议 > php-odbc ##应用程序编程接口 > php-pear ##扩展应用代码库 > php-xml php-xmlrpc ##xml文件 > php-mbstring ##多字节字符串 > php-snmp ##管理端开发 > php-soap ##SOAP 扩展可以用来提供和使用 Web Services > curl curl-devel ##支持数据文件下载工具 > php-bcmath ##BCMath库来支持更加精确的计算
[root@lamp ~]# cd /var/www/html/ ##切换到站点 [root@lamp html]# vim index.php ##编辑php网页内容 <?php phpinfo(); ?>
[root@lamp html]# vim index.php ##编辑php网页内容 <?php echo "apache web !" ?>
[root@localhost ~]# smbclient -L //192.168.100.3/ ##远程共享访问 Enter SAMBA\root's password: Sharename Type Comment --------- ---- ------- LNMP-C7 Disk [root@localhost ~]# mount.cifs //192.168.100.3/LNMP-C7 /mnt ##挂载到/mnt目录下
[root@localhost ~]# cd /mnt ##切换到挂载点目录 [root@localhost mnt]# ls Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz mysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz [root@localhost mnt]# tar zxvf nginx-1.12.2.tar.gz -C /opt ##解压Nginx源码包到/opt下 [root@localhost mnt]# cd /opt/ ##切换到解压的目录下 [root@localhost opt]# ls nginx-1.12.2 rh
[root@localhost opt]# yum -y install \ gcc \ //c语言 gcc-c++ \ //c++语言 pcre-devel \ //pcre语言工具 zlib-devel //数据压缩用的函式库
[root@localhost opt]# useradd -M -s /sbin/nologin nginx ##创建程序用户,安全不可登陆状态 [root@localhost opt]# id nginx uid=1001(nginx) gid=1001(nginx) 组=1001(nginx) [root@localhost opt]# cd nginx-1.12.0/ ##切换到nginx目录下 [root@localhost nginx-1.12.0]# ./configure \ ##配置nginx > --prefix=/usr/local/nginx \ ##安装路径 > --user=nginx \ ##用户名 > --group=nginx \ ##用户组 > --with-http_stub_status_module ##状态统计模块
[root@localhost nginx-1.12.0]# make ##编译 ... [root@localhost nginx-1.12.0]# make install ##安装 ... [root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ ##创建软连接让系统识别nginx启动脚本
[root@localhost nginx]# cd /etc/init.d/ ##切换到启动配置文件目录 [root@localhost init.d]# ls functions netconsole network README [root@localhost init.d]# vim nginx ##编辑启动脚本文件 #!/bin/bash # chkconfig: - 99 20 ##注释信息 # description: Nginx Service Control Script PROG="/usr/local/nginx/sbin/nginx" ##设置变量为nginx命令文件 PIDF="/usr/local/nginx/logs/nginx.pid" ##设置变量PID文件 进程号为5346 case "$1" in start) $PROG ##开启服务 ;; stop) kill -s QUIT $(cat $PIDF) ##关闭服务 ;; restart) ##重启服务 $0 stop $0 start ;; reload) ##重载服务 kill -s HUP $(cat $PIDF) ;; *) ##错误输入提示 echo "Usage: $0 {start|stop|restart|reload}" exit 1 esac exit 0 [root@localhost init.d]# chmod +x /etc/init.d/nginx ##给启动脚本执行权限 [root@localhost init.d]# chkconfig --add nginx ##添加到service管理器中 [root@localhost init.d]# service nginx stop ##就可以使用service控制nginx [root@localhost init.d]# service nginx start
[root@localhost init.d]# yum install elink -y ##安装软件 [root@localhost init.d]# netstat -ntap | grep 80 ##查看Nginx端口 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 44663/nginx: master [root@localhost init.d]# systemctl stop firewalld.service ##关闭防火墙 [root@localhost init.d]# setenforce 0 [root@localhost init.d]# elinks http://192.168.13.140/ ##测试网页
[root@localhost init.d]# vim /usr/local/nginx/conf/nginx.conf ##修改配置文件 location ~ \.php$ { ##找到此处将注释去除,开启动静分离 proxy_pass http://192.168.13.139; ##填写动态处理的Apache的服务器地址 } [root@localhost init.d]# service nginx stop ##关闭 [root@localhost init.d]# service nginx start ##开启
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。