Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy Nginx+Apache static and dynamic separation

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to deploy Nginx+Apache dynamic and static separation, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Introduction to static and dynamic separation of Nginx

The static processing capacity of Nginx is very strong, but the dynamic processing capacity is insufficient, so the static and dynamic separation technology is commonly used in enterprises.

Static and dynamic separation for PHP

Static pages are handed over to Nginx for processing

Dynamic pages are handed over to PHP-FPM module or Apache for processing

In the configuration of Nginx, different processing methods of static and dynamic pages are realized through location configuration segment combined with regular matching.

Reverse agency principle

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

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

The most important instruction of Nginx when implementing reverse proxy function is proxy_ pass, which can and can schedule user requests to upstream servers according to URI, client parameters or other processing logic.

Configure nginx to realize static and dynamic separation

In this case, according to the needs of the enterprise, the static and dynamic separation is realized by configuring Nginx, and the request for the php page is forwarded to LAMP for processing, while the static page is handed over to Nginx for processing to achieve static and dynamic separation.

The architecture is shown in the figure

Configuration step

1. Set up and debug the backend LAMP environment

① installs the Apache service

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

② sets the permissions of the http service at the firewall

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

③ install mariadb

Mariadb database management system is a branch of MySQL and is mainly maintained by the open source community. The purpose of licensing mariadb with GPL is to be fully compatible with MySQL, including API and the 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

⑤ installs php and supported 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

⑥ changes the main page of the web page

[root@localhost ~] # cd / var/www/html [root@localhost html] # vim index.php [root@localhost html] # systemctl restart httpd

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

2. Compile and install nginx

① installation support softwar

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

② create and run users and groups

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

③ compilation and installation

[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 instart init.dGinxUnix instart PROG:-99 2 pound description: Ngins Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" PIDF= "/ usr/local/nginx/logs/nginx.pid" case "$1" instart) $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 1esacexit 0 [root@localhost ~] # chmod + x / etc/init.d/nginx [root@localhost ~] # chkconfig-- add nginx [root@localhost ~] # service nginx start

⑤ Startup Service

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

⑥ configures 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

Thank you for reading this article carefully. I hope the article "how to deploy Nginx+Apache separation" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report