In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Realize the dynamic and static separation analysis between apache and 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.
For the static and dynamic separation of PHP, the static page is handed over to Nginx for processing, and the dynamic page is 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.
The simple schematic diagram is as follows:
In this experiment, two virtual machines will be used to simulate LNMP and NGINX respectively.
The first is the erection of LAMP
LAMP end
Install the http service
[root@localhost ~] # hostnamectl set-hostname LAMP / / change hostname [root@localhost ~] # su [root@lamp ~] # yum install httpd httpd-devel-y [root@lamp ~] # systemctl start httpd.service [root@lamp ~] # firewall-cmd-- zone=public-- add-service=http-- permanent / / Firewall is allowed through success [root@lamp ~] # firewall-cmd-- zone=public-- add-service=https-- permanent success [root@lamp ~] # firewall-cmd-- reload success
Install the mariadb database
Overview:
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, making it an easy replacement for MySQL.
[root@lamp ~] # yum install mariadb mariadb-server mariadb-libs mariadb-devel-y [root@lamp ~] # systemctl start mariadb.service [root@lamp ~] # mysql_secure_installation / / set 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 currentpassword for the root user. If you've just installed MariaDB, andyou 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): / / enter to proceed to the next step OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [root] y / / create a new root management password, select yNew password: / / enter the same password twice to Re-enter new password: Password updated administrative fully reloded password ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [YBO] n / / Delete anonymous users? (select n). Skipping.Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [YBO] n / / whether to allow remote root login, select n. Skipping.By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [YBO] n / / Select n. Skipping.Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [YBO] y / / do you want to refresh? (select y). Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!
Install PHP tools
[root@lamp ~] # yum-y install php / / install PHP tool [root@lamp] # yum install php-mysql-y / / establish the relationship between php and database [root@lamp ~] # yum-y install\ php-gd\ php-ldap\ php-odbc\ php-pear\ php-xml\ php-xmlrpc\ php-mbstring\ php-snmp\ php-soap\ curl curl-devel\ php-bcmath
Create a http site
[root@lamp ~] # cd / var/www/html/ go to the http site directory [root@lamp html] # ll / / the total consumption is empty at this time 0 [root@lamp html] # vim index.php / / add [root@lamp html] # systemctl restart httpd.service to the new home page
At this point, the dynamic web page of php can be viewed by using the test machine, which proves that the LAMP architecture is successful. Here are the settings of nginx.
Nginx end
Open another virtual machine as the nginx side
Compile and install nginx manually
[root@localhost ~] # hostnamectl set-hostname nginx / / change hostname [root@localhost ~] # su [root@nginx mnt] # tar zxvf nginx-1.12.0.tar.gz-C / opt [root@nginx mnt] # cd / opt/nginx-1.12.0/ [root@nginx nginx-1.12.0] # useradd-M-s / sbin/nologin nginx / / create a programmatic user [root@nginx nginx-1.12.0] # Yum-y install\ gcc gcc-c++\ pcre pcre-devel\ zlib-devel\ expat-devel [root@nginx nginx-1.12.0] #. / configure\ >-- prefix=/usr/local/nginx\ >-- user=nginx\ >-- group=nginx\ >-- with-http_stub_status_module [root@nginx nginx-1.12.0] # make & & make install / / compiler installation
Write a startup script
[root@nginx nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ create soft links to facilitate identification [root@nginx nginx-1.12.0] # vim / etc/init.d/nginx add #! / bin/bashwenjian= "/ usr/local/nginx/sbin/nginx" pid= "/ usr/local/nginx/logs/nginx.pid" case $1 instart) $wenjian;; stop) kill-s QUIT $(cat $pid) Restart) $0 stop $0 start;;reload) kill-s HUP $(cat $pid);; *) echo "Please,try again" exit 1 Esacexit 0 [root@nginx nginx-1.12.0] # chmod + x / etc/init.d/nginx [root@nginx init.d] # service nginx start [root@nginx init.d] # netstat-atnp | grep 80tcp 0 0 0.0.0.0 chmod 80 0.0.0.0 LISTEN 8638/nginx: master [root@nginx init.d] # systemctl stop firewalld.service [root@nginx init.d] # setenforce 0
Verify the nginx service
At this point, when we access it through the test machine, we can get the following interface:
However, if you visit a dynamic web page in php format, there will be a 404 access error.
To solve this problem, the following experiment was introduced to set the static and dynamic separation in the nginx configuration file.
Nginx end
[root@nginx init.d] # cd / usr/local/nginx/conf [root@nginx conf] # vim nginx.conf / / modify lines 59 to 61 of the configuration file, uncomment, and modify location ~\ .php$ {proxy_pass http://192.168.142.128; # apache server address} wq save exit [root@nginx nginx] # service nginx stop / / restart the service [root@nginx nginx] # service nginx start
At this point, the separation of movement and movement is all completed.
Experimental verification
Dynamic web page
Static web page
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.