Nginx configuration of static and dynamic separation

I. Overview

Nginx static processing power is very strong, but the lack of dynamic processing power, you can configure a reverse proxy dynamic page requests to the Apache.

Second, the experimental procedures

Install apache ---- "" Install Database ---- "" ---- "" Configure php Home ----- "" install nginx ---- "" Configure nginx reverse proxy ---- " "dynamic simulation test request

Third, install apache

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

Modify apache listening on port 8080 (since all the services installed on a single machine);
turn off the firewall, start the httpd service.

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

Here Insert Picture Description

[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce  0
[root@localhost ~]# systemctl start httpd    ###启动httpd
[root@localhost nginx-1.12.2]#  netstat -ntap | grep httpd
tcp        0      0 192.168.5.140:8080      0.0.0.0:*               LISTEN      47052/httpd         

Fourth, the installation of lightweight database mariadb

[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
[root@localhost ~]# systemctl start  mariadb   ##启动数据库
[root@localhost ~]# netstat -ntap | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      4301/mysqld         
[root@localhost ~]# 

Configuration database

[root@localhost ~]# mysql_secure_installation
Enter current password for root (enter for none):   #回车
Set root password? [Y/n] y  ##是否设置密码
New password:     ####自己设置密码
Re-enter new password:   ###确认密码
Remove anonymous users? [Y/n] n   ##是否删除匿名用户
Disallow root login remotely? [Y/n] n  ##是否拒绝远程root登陆
Remove test database and access to it? [Y/n] n  ###是否删除测试
Reload privilege tables now? [Y/n] y  ##是否重新加载
 ... Success!

Install php

[root@localhost ~]# yum -y install php
[root@localhost ~]# yum install php-mysql -y ##安装php和mysql链接包
[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
##环境工具包

Php configuration Home

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

Restart httpd, php verification page

[root@localhost html]# systemctl restart httpd

Here Insert Picture Description

Fifth, install nginx

Installation environment package

[root@localhost html]# yum -y install gcc gcc-c++ pcre-devel zlib-devel

In nginx official website to download the installation package (here I use the version 1.12.2), extract to opt directory, create a user program .

[root@localhost LNMP-C7]# tar zxvf nginx-1.12.2.tar.gz -C
[root@localhost LNMP-C7]# useradd -M -s /sbin/nologin nginx

/Opt/nginx-1.12.2/ into the unzipped directory configure script

[root@localhost LNMP-C7]# cd /opt/nginx-1.12.2/
[root@localhost nginx-1.12.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module

Compile and install

[root@localhost nginx-1.12.2]# make && make install

Create a soft easy connection management command to start the nginx service.

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin
[root@localhost nginx-1.12.2]# nginx  ##启动nginx
[root@localhost nginx-1.12.2]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7996/nginx: master  

Verification nginx Home
Here Insert Picture Description

Sixth, configure static and dynamic separation

[root@localhost nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf

Here Insert Picture Description

Seven, dynamic simulation test request

Restart nginx service

[root@localhost nginx-1.12.2]# killall -1 nginx  ##重启nginx服务
[root@localhost nginx-1.12.2]#  netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      46918/nginx: master 

Dynamic simulation request php web page, found this request to jump directly to the apache Home
Here Insert Picture Description

Published 43 original articles · won praise 56 · views 7903

Guess you like

Origin blog.csdn.net/weixin_42953006/article/details/103686463