Detailed example of deploying Nginx+Apache dynamic and static separation

Detailed example of deploying Nginx+Apache dynamic and static separation

Introduction to Nginx dynamic and static separation

Nginx has strong static processing capabilities, but insufficient dynamic processing capabilities. Therefore, enterprises often use dynamic and static separation technology to separate PHP from dynamic and static.

  • Static pages are handled by Nginx
  • Dynamic pages are processed by PHP-FPM module or Apache

In Nginx configuration, different processing methods for static and dynamic pages are implemented through the location configuration segment and regular matching.

Reverse proxy principle

Nginx can not only be used as a Web server, but also has the functions of reverse proxy, load balancing and caching.

Nginx uses the proxy module to proxy the client's request to the upstream server. At this time, the connection between nginx and the upstream server is carried out through the http protocol.

The most important instruction of Nginx when implementing the reverse proxy function is proxy_pass, which can dispatch user requests to the upstream server according to the URI, client parameters or other processing logic.

Configure nginx to achieve dynamic and static separation

In this case, according to the needs of the enterprise, Nginx will be configured to achieve dynamic and static separation. Requests for PHP pages will be forwarded to LAMP for processing, while static pages will be handed over to Nginx for processing to achieve dynamic and static separation.

The architecture is shown in the figure

insert image description here

Configuration steps

1. Set up and debug the backend LAMP environment

①Install Apache service

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

②Set the permissions for the http service on the firewall

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=https
success   
[root@localhost ~]# firewall-cmd --reload 
success
[root@localhost ~]# systemctl start httpd

③Install mariadb

The mariadb database management system is a branch of MySQL, mainly maintained by the open source community and licensed under the GPL. The purpose of mariadb is to be fully compatible with MySQL, including API and command line, so that it can easily become a substitute for MySQL.

[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
[root@localhost ~]# systemctl start mariadb.service

④MySQL Security Configuration Wizard

[root@localhost ~]# mysql_secure_installation

⑤Install PHP and supporting software

[root@localhost ~]# yum install php -y
[root@localhost ~]# yum install php-mysql -y
[root@localhost ~]# yum install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath -y

⑥Change the main page of the website

[root@localhost ~]# cd /var/www/html
[root@localhost html]# vim index.php
<?php
  echo "this is apache test web";
?>

[root@localhost html]# systemctl restart httpd

⑦Access test, enter the URL http://192.168.150.214/index.php

insert image description here

2. Compile and install nginx

①Install support software

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

②Create running users and groups

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

③Compile and install

[root@localhost LNMP-C7]# tar zxvf nginx-1.12.2.tar.gz -C /opt
[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

[root@localhost nginx-1.12.2]# make && make install
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin

④Service management control

[root@localhost ~]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: -99 20
# description: Ngins 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@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# service nginx start

⑤Start the service

[root@nginx ~]# systemctl stop firewalld.service
[root@nginx ~]# setenforce 0
[root@nginx ~]# service nginx start

⑥Configure nginx to handle dynamic page requests

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

[root@nginx ~]# service nginx restart

⑦Access test

insert image description here
insert image description here

Summarize

The above is a detailed example of deploying Nginx+Apache dynamic and static separation introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Basic configuration example of Nginx with Apache or Tomcat for dynamic and static separation
  • Using Nginx+uWsgi to separate the dynamic and static parts of Python's Django framework site
  • Simple implementation of nginx+tomcat reverse proxy and dynamic and static separation
  • Detailed explanation of nginx to separate static and dynamic tomcat
  • nginx realizes load balancing and dynamic and static separation
  • Nginx sample code for implementing dynamic and static separation
  • Sample code for nginx to achieve dynamic and static separation
  • Nginx implements dynamic and static separation example explanation
  • Nginx dynamic and static separation implementation case code analysis
  • Detailed explanation of the process of realizing dynamic and static separation in Springmvc nginx
  • Docker Nginx container and Tomcat container to achieve load balancing and dynamic and static separation operations
  • Analysis of the principle of Nginx+Tomcat to achieve load balancing and dynamic and static separation
  • The principle and configuration of Nginx load balancing and dynamic and static separation
  • Example of how nginx implements dynamic and static separation
  • Detailed instructions for nginx from installation to configuration (installation, security configuration, anti-hotlinking, dynamic and static separation, HTTPS configuration, performance optimization)
  • Implementation of Nginx+Tomcat load balancing and dynamic and static separation cluster
  • Server load balancing nginx+tomcat to achieve dynamic and static separation
  • Nginx dynamic and static separation configuration implementation and description

<<:  How to unify the character set on an existing mysql database

>>:  A simple example of using Vue3 routing VueRouter4

Recommend

CSS to achieve zoom in and out close button (example code)

This effect is most common on our browser page. L...

MySQL storage engine basics

In the previous article, we talked about MySQL tr...

Building a Redis cluster on Docker

Table of contents 1. Pull the image 2. Create a R...

Solution to interface deformation when setting frameset height

Currently I have made a project, the interface is ...

Summary of 10 must-see JavaScript interview questions (recommended)

1.This points to 1. Who calls whom? example: func...

Web page comments cause text overflow in IE

The experimental code is as follows: </head>...

An example of how Vue implements four-level navigation and verification code

Effect: First create five vue interfaces 1.home.v...

Comprehensive summary of mysql functions

Table of contents 1. Commonly used string functio...

In-depth understanding of MySQL global locks and table locks

Preface According to the scope of locking, locks ...

Detailed explanation of the payment function code of the Vue project

1. Alipay method: Alipay method: Click Alipay to ...

Use href to simply click on a link to jump to a specified place on the page

After clicking the a tag in the page, you want to ...

Detailed tutorial on installing centos8 on VMware

CentOS official website address https://www.cento...

MySQL optimization: how to write high-quality SQL statements

Preface There are a lot of information and method...

Flex layout achieves fixed number of rows per line + adaptive layout

This article introduces the flex layout to achiev...

Detailed explanation of mysql download and installation process

1: Download MySql Official website download addre...