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.
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 Configuration steps 1. Set up and debug the backend LAMP environment ①Install Apache service ②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 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 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! You may also be interested in:
|
<<: How to unify the character set on an existing mysql database
>>: A simple example of using Vue3 routing VueRouter4
This effect is most common on our browser page. L...
In the previous article, we talked about MySQL tr...
Table of contents 1. Pull the image 2. Create a R...
Currently I have made a project, the interface is ...
1.This points to 1. Who calls whom? example: func...
The experimental code is as follows: </head>...
Effect: First create five vue interfaces 1.home.v...
Table of contents 1. Commonly used string functio...
Preface According to the scope of locking, locks ...
1. Alipay method: Alipay method: Click Alipay to ...
After clicking the a tag in the page, you want to ...
CentOS official website address https://www.cento...
Preface There are a lot of information and method...
This article introduces the flex layout to achiev...
1: Download MySql Official website download addre...