Centos7Nginx + LAMPビルド動的分離


準備オーケー:

ホスト オペレーティング・システム IPアドレス
ランプ Centos7 192.168.1.1
Nginx Centos7 192.168.1.2

1.LAMPアーキテクチャを構築します

挂光盘,并搭建yum源

1.Apacheをインストールします

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

2.Mysqlをインストールします

[root@LAMP ~]# yum -y install mariadb mariadb-server mariadb-libs mariadb-devel   
[root@LAMP ~]# systemctl start mariadb       #开启mariadb数据库
[root@LAMP ~]# mysql_secure_installation     #数据库初始化设置
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

Enter current password for root (enter for none):     #直接回车
OK, successfully used password, moving on...
Set root password? [Y/n] y                       #是否设置root密码
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
Remove anonymous users? [Y/n] n                  #是否移除匿名用户
 ... skipping.
Disallow root login remotely? [Y/n] n            #是否不允许root远程登录
 ... skipping.
Remove test database and access to it? [Y/n] n   #是否移除测试数据库
 ... skipping.
Reload privilege tables now? [Y/n] y             #是否重载数据库表
 ... Success!

3.PHPをインストールします

[root@LAMP ~]# yum -y install php	      #安装php服务
[root@LAMP ~]# yum -y install php-mysql       #安装PHP组件,使PHP支持MySQL
[root@LAMP ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath    
[root@LAMP ~]# vim /var/www/html/index.php    #编写php网页
<?php
  phpinfo();
?>
[root@LAMP ~]# systemctl start httpd          #开启httpd服务

ブラウザを使用してテストにアクセスします。
ここに写真の説明を挿入

次に、Nginxをビルドします

次のリンクからNginxソフトウェアパッケージをダウンロードし
ます。https
://pan.baidu.com/s/1QIQvRKMyGkxA_FXcadnLUQ抽出コード:p83s
挂光盘,并搭建yum源

[root@Nginx ~]# yum -y install pcre pcre-devel zlib-devel gcc gcc-c++
[root@Nginx ~]# rz    #上传Nginx软件包
z waiting to receive.**B0100000023be50
[root@Nginx ~]# ls
anaconda-ks.cfg       nginx-1.12.0.tar.gz  模板  图片  下载  桌面
initial-setup-ks.cfg  公共                 视频  文档  音乐
[root@Nginx ~]# tar zxf nginx-1.12.0.tar.gz     #解压
[root@Nginx ~]# cd nginx-1.12.0/		#进入解压目录
[root@Nginx nginx-1.12.0]# useradd -M -s /sbin/nologin nginx     #创建nginx运行用户
配置,编译,并安装:
[root@Nginx nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make && make install
创建软链接优化执行路径:
[root@Nginx nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
编写Nginx服务脚本:
[root@Nginx nginx-1.12.0]# vim /etc/init.d/nginx
#!/bin/bash
#chkconfig:-  99 20
#description:Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
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@Nginx nginx-1.12.0]# chmod +x /etc/init.d/nginx           #添加可执行权限
[root@Nginx nginx-1.12.0]# chkconfig --add /etc/init.d/nginx    #添加为系统服务
[root@Nginx nginx-1.12.0]# systemctl start nginx		#开启nginx服务
[root@Nginx nginx-1.12.0]# yum -y install elinks		#可以在命令行连接网页
[root@Nginx nginx-1.12.0]# elinks http://localhost

ここに写真の説明を挿入

Nginxメイン構成ファイルを変更します

[root@Nginx nginx-1.12.0]# vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
    
    
            proxy_pass   http://192.168.1.1;
        }

ここに写真の説明を挿入

[root@Nginx nginx-1.12.0]# systemctl restart nginx    #重启nginx服务

3、動的および静的分離を確認します

1.静的ページindex.html

ここに写真の説明を挿入

2.動的ページindex.php

ここに写真の説明を挿入

おすすめ

転載: blog.csdn.net/weixin_46902396/article/details/109319137