CentOS7システム構成nginxの+ Apacheは、静的および動的分離(本当!)となります

nginxの静的及び動的分離紹介

  • nginxの静的な処理能力は非常に強いですが、ダイナミックな処理能力の不足、企業内のため、多くの場合、静的および動的な分離技術。

  • nginxのは、静的なページ、PHP-FPM Apacheモジュールまたはプロセスへの動的ページを処理します。

  • nginxの構成では、静的および動的なページと異なる処理を実現するために、場所の設定との定期的な部分で一致しています。

LAMPアーキテクチャ建物

yumを手動でコンパイルせずにインストールするのは簡単としてインストールを使用して直接実験。2台の仮想マシンは、nginxのLAMPアーキテクチャとサービスを設定したと。

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

[root@localhost ~]# yum install httpd httpd-devel -y
.........//省略安装过程
[root@localhost ~]#

2.サービス、ファイアウォールの設定Firewalld

[root@localhost ~]# systemctl start httpd.service   //开启服务
[root@localhost ~]# 
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http  //放通http服务
success
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=https   //放通https服务
success
[root@localhost ~]# firewall-cmd --reload    //重载防火墙
success
[root@localhost ~]#

mariadbデータベースをインストールします3。

MariaDBのMySQLデータベース管理システムは、主にメンテナンスにおけるオープンソースコミュニティによって、支店で、GPLを使用する目的は、MariaDBは、それが簡単にMySQLの代わりになることができるように、APIやコマンドラインを含む、MySQLのと完全に互換性があるライセンスさ。

[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
...........//省略安装过程
[root@localhost ~]#

4.オープンデータベースサービス

[root@localhost ~]# systemctl start mariadb.service 
[root@localhost ~]#

データベースが提供されています

[root@localhost ~]# mysql_secure_installation     //对数据库进行设置

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):    //给root管理员设定密码,直接回车
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   //是否设置,选择y
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   //是否删除匿名用户,选择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   //是否拒绝root用户远程登陆,选择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   //是否删除测试数据库,选择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   //是否加载权限列表,选择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をインストールします。6.

[root@localhost ~]# yum -y install php
.......//省略过程
[root@localhost ~]#

7.コネクタのインストールパッケージPHPとMySQL

[root@localhost ~]# yum install php-mysql -y
........//省略过程
[root@localhost ~]#

8. PHPプラグインをインストール

[root@localhost ~]# 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@localhost ~]#

9.テストPHPホーム

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

CentOS7システム構成nginxの+ Apacheは、静的および動的分離(本当!)となります

10.テストは、変更されたページファイルを終了しました

[root@localhost html]# vim /var/www/html/index.php
<?php
 echo "this is apache web!"
?>
[root@localhost html]# systemctl restart httpd.service 
[root@localhost html]# 

CentOS7システム構成nginxの+ Apacheは、静的および動的分離(本当!)となります

nginxのビルドサービス

ホスト名を変更します。1.

[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# su
[root@nginx ~]# 

「は/ opt /」ディレクトリに2.抽出nginxのソースパッケージ

[root@nginx ~]# mkdir /mnt/tools
[root@nginx ~]# mount.cifs //192.168.100.50/tools /mnt/tools/
Password for root@//192.168.100.50/tools: 
[root@nginx ~]# cd /mnt/tools/LNMP/
[root@nginx LNMP]# ls
Discuz_X3.4_SC_UTF8.zip  mysql-boost-5.7.20.tar.gz  nginx-1.12.2.tar.gz  php-7.1.10.tar.bz2  php-7.1.20.tar.gz
[root@nginx LNMP]# tar zxvf nginx-1.12.2.tar.gz -C /opt/
........//省略过程
[root@nginx LNMP]#

3.インストール環境のパッケージ

[root@nginx LNMP]# cd /opt/
[root@nginx opt]# ls
nginx-1.12.2  rh
[root@nginx opt]# cd nginx-1.12.2/
[root@nginx nginx-1.12.2]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@nginx nginx-1.12.2]# 
[root@nginx nginx-1.12.2]# yum install -y gcc gcc-c++ pcre-devel zlib-devel
.........//省略过程
[root@nginx nginx-1.12.2]#

ユーザーnginxの作成3.

[root@nginx nginx-1.12.2]# useradd -M -s /sbin/nologin nginx
[root@nginx nginx-1.12.2]# 

4.設定nginxのサービス、およびコンパイルとインストール

[root@nginx nginx-1.12.2]# ./configure \   //配置服务
> --prefix=/usr/local/nginx \   //安装路径
> --user=nginx \   //属主
> --group=nginx \   //数据
> --with-http_stub_status_module   //启用统计模块

[root@localhost nginx-1.12.2]# make && make install   //编译安装
.........//省略编译过程
[root@localhost nginx-1.12.2]# 

5. nginxの最適化サービス管理

[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  //优化nginx命令路径
[root@nginx nginx-1.12.2]# 
[root@nginx nginx-1.12.2]# vim /etc/init.d/nginx    //制作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.2]#
[root@nginx nginx-1.12.2]# chmod +x /etc/init.d/nginx    //添加执行权限
[root@nginx nginx-1.12.2]# chkconfig --add nginx   //添加让service能够识别
[root@nginx nginx-1.12.2]# 

6.電源を入れnginxのサービス

[root@nginx nginx-1.12.2]# service nginx start     //开启服务
[root@nginx nginx-1.12.2]# netstat -ntap | grep 80   //查看端口
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      58696/nginx: master 
[root@nginx nginx-1.12.2]#
[root@nginx nginx-1.12.2]# systemctl stop firewalld.service    //关闭防火墙
[root@nginx nginx-1.12.2]# setenforce 0
[root@nginx nginx-1.12.2]# 

テストnginxのWebサイトにelinksツールをインストール7.

[root@nginx nginx-1.12.2]# yum install elinks -y
..........//省略安装过程
[root@nginx nginx-1.12.2]#
[root@nginx nginx-1.12.2]# elinks http://192.168.52.132/
[root@nginx nginx-1.12.2]#

CentOS7システム構成nginxの+ Apacheは、静的および動的分離(本当!)となります

8.ホストテストnginxのウェブサイト

CentOS7システム構成nginxの+ Apacheは、静的および動的分離(本当!)となります

静的および動的な分離を達成

1. nginxのプロキシサービスプロファイルを追加します。

[root@nginx nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf
        location ~ \.php$ {
            proxy_pass   http://192.168.52.131;   //代理地址
        }
[root@nginx nginx-1.12.2]# service nginx stop 
[root@nginx nginx-1.12.2]# service nginx start 
[root@nginx nginx-1.12.2]# 

アドレス(静的リソース)2.アクセスnginxのサービス

CentOS7システム構成nginxの+ Apacheは、静的および動的分離(本当!)となります

3.アクセスnginxのサービスアドレス(動的リソース)

CentOS7システム構成nginxの+ Apacheは、静的および動的分離(本当!)となります

おすすめ

転載: blog.51cto.com/14449541/2453229