91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CentOS7系統配置Nginx服務+Apache動靜分離(實戰!)

發布時間:2020-03-30 17:39:45 來源:網絡 閱讀:1010 作者:wx5d2c2d660c282 欄目:系統運維

Nginx動靜分離介紹

  • Nginx的靜態處理能力很強,但是動態處理能力不足,因此,在企業中常用動靜分離技術;

  • 靜態頁面交給Nginx處理,動態頁面交給PHP-FPM模塊或Apache處理;

  • 在Nginx的配置中,是通過location配置段配合正則匹,配實現靜態與動態頁面的不同處理方式。

搭建LAMP架構

為方便實驗直接用yum安裝,不用手工編譯安裝。用兩臺虛擬機,分別搭建LAMP架構和Nginx服務。

1.安裝Apache服務

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

3.安裝mariadb數據庫

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 ~]#

5.進行數據庫設置

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

6.安裝PHP

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

2.解壓nginx源碼包到“/opt/”目錄

[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]#

3.創建nginx用戶

[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]# 

7.安裝elinks工具測試nginx網站

[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動靜分離(實戰!)

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

延安市| 江北区| 新竹市| 家居| 金门县| 从江县| 锡林郭勒盟| 青州市| 望江县| 松原市| 鹤岗市| 共和县| 罗甸县| 瓦房店市| 饶阳县| 吴堡县| 周口市| 平湖市| 托克逊县| 衡阳县| 新乡县| 平武县| 宁明县| 宁乡县| 马龙县| 都昌县| 五河县| 菏泽市| 凌海市| 永清县| 哈密市| 龙里县| 东明县| 芮城县| 蓝田县| 太康县| 清河县| 随州市| 陈巴尔虎旗| 武山县| 大姚县|