In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to build Nginx dynamic and static separation in Linux system". In daily operation, I believe that many people have doubts about how to build Nginx dynamic and static separation in Linux system. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to build Nginx dynamic and static separation in Linux system". Next, please follow the editor to study!
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. At this time, nginx and. The upstream server is connected through the http protocol
The most important instruction of Nginx when implementing the reverse proxy function is proxy_ _ pass, which can and can schedule user requests to the upstream server according to URI, client parameters or other processing logic.
Configure static and dynamic separation
Set up and debug the back-end LAMP environment
Install and configure Nginx to handle static page requests, adding to the server {}; section
[root@nginx php5] # vim / usr/local/httpd/conf/nginx.conf location ~. *\. (gifiglipeglbmp | swf) ${root html; index index.html index.htm;}
Configure Nginx to handle dynamic page requests and add them to server {};
In Apache. New test.php for working directory
Restart Nginx and test
[root@nginx php5] # vim / usr/local/httpd/conf/nginx.conf server {. Location ~\ .php$ {proxy_ pass http://192.168.9.237:8080; / / LAMP's IP address. Configure an instance
Two Linux virtual machines are enabled, one configuring Nginx and the other configuring LANM architecture. The Nginx service handles static access information and LAMP handles dynamic access information when the client accesses nginx web pages.
First build the lamp architecture in a Linux system, where yum is used to install the lamp architecture
Yum install httpd httpd-devel-y has loaded the plug-in: fastestmirror, langpacksLoading mirror speeds from cached hostfile...// omits part of the content. Installed: httpd.x86_64 0VOR 2.4.6-90.el7.centos httpd-devel.x86_64 0RU 2.4.6-90.el7.centos... / / omit part of the content. Over! [root@localhost ~] # firewall-cmd-- permanent-- zone=public-- add-service=httpsuccess / / configure firewall to allow http service to reload firewall success in public area via [root@localhost ~] # firewall-cmd-- permanent-- zone=public-- add-service=httpssuccess / / configure fire wall to allow https service to reload firewall success in public area via [root@localhost ~] # firewall-cmd-- reload / / [root@localhost ~] # systemctl start httpd.service / / start the http service
Access the httpd service at the client to see if the service is started successfully
Install mariadb (mariadb is a branch of MySQL and has the same function as MySQL)
[root@localhost ~] # yum install mariadb mariadb-server mariadb-libs mariadb-devel-y has loaded the plug-in: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn...// omits part of the content. Installed: mariadb.x86_64 1VR 5.5.64-1.el7 mariadb-devel.x86_64 1VR 5.5.64-1.el7 mariadb-server.x86_64 1VR 5.5.64-1.el7 over! [root@localhost ~] # systemctl start mariadb / / start the mariadb service [root@localhost ~] # netstat-ntap | grep 3306tcp 00 0.0.0.0mariadb 3306 0.0.0.0mariadb * LISTEN 2519/mysqld [root@localhost ~] # mysql_secure_installation / / set database 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): / / ask whether to set a password for root users, and enter 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 directly? [industry] y / / whether to set the password or not, enter y to confirm the password Re-enter new password: / / enter the password Re-enter new password: / / enter the password again Password updated fully loaded Reloading privilege tables.. ... 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 / / asks whether to delete anonymous users, enter n, do not delete. 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? [YPAPO] n / / asks if root users are denied remote login, enter n, do not refuse. 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 / / asks if you want to delete the test database, enter n, do not delete. Skipping.Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [YOrganization] y / / asks if you want to reload the database, enter y, reload. Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB! / / complete the setup
Install PHP
[root@localhost ~] # yum-y install php / / install the php service loaded plug-ins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn...// omits part of the content. Installed: php.x86_64 0 5.4.16-46.1.el7_7. / / omit part of the content. Over! [root@localhost ~] # yum install php-mysql-y / / install php and mysql connection pack loaded plug-ins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn * extras: ftp.sjtu.edu.cn...// omits part of the content. Installed: php-mysql.x86_64 0VOR 5.4.16-46.1.el7_7 installed as a dependency: php-pdo.x86_64 0RV 5.4.16-46.1.el7_7 over! [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 / / install php environment package loaded plug-ins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn...// omitted part of the content. Installed: libcurl-devel.x86_64 0VOR 7.29.0-54.el7 php-bcmath.x86_64 0VR 5.4.16-46.1.el7_7 php-gd.x86_64 0V 5.4.16-46.1.el7_7 php-ldap.x86_64 0V 5.4.16-46.1.el7_7 php-mbstring.x86_64 0VOR 5.4.16-46.1.el7_7 php-odbc.x86_64 0RV 5.4.16-46.1.el7_7 php-pear.noarch 1RU 1.9.4-21.el7 php-snmp.x86_64 0RU 5.4.16-46.1.el7_7 php-soap.x86_64 0RV 5.4.16-46.1.el7 _ 7 php-xml.x86_64 0lug 5.4.16-46.1.el7_7 php-xmlrpc.x86_64 0vir 5.4.16-46.1.el7_7... / / omit some of the contents. Over! [root@localhost ~] # cd / var/www/html / / enter the web site [root@localhost html] # vim index.php / / Edit php page content: wq [root@localhost html] # systemctl restart httpd.service / / restart the http service
Test whether the LAMP mechanism is installed successfully in the client
Install Nginx
Install the Nginx service on another Linux system
[root@localhost ~] # hostnamectl set-hostname nginx / / to distinguish between changing the Linux host name [root@localhost ~] # su [root@nginx ~] # / / the change succeeded [root@nginx nginx-1.12.2] # yum install gcc gcc-c++ make pcre-devel zlib-devel-y / / the installation environment package has loaded the plug-in: fastestmirror LangpacksLoading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn...// omits part of the content. Installed: gcc.x86_64 0VOR 4.8.5-39.el7 gcc-c++.x86_64 0VOR 4.8.5-39.el7 pcre-devel.x86_64 0RH 8.32-17.el7 zlib-devel.x86_64 0RO 1.2.7-18.el7...// omits part of the content. Over! [root@nginx ~] # useradd-M-s / sbin/nologin nginx / / user [root@nginx ~] # mount.cifs / / 192.168.100.10/lnmp / mnt/ Mount the host source package directory to the mnt directory Password for root@//192.168.100.10/lnmp: [root@nginx ~] # cd / mnt/ enter the mnt directory [ Root@nginx mnt] # tar zvxf nginx-1.12.2.tar.gz-C / opt/ decompress the source code package. / / omit part of the content. Nginx-1.12.2/auto/cc/msvcnginx-1.12.2/auto/cc/namenginx-1.12.2/auto/cc/owcnginx-1.12.2/auto/cc/sunc [root@nginx mnt] # cd / opt/nginx-1.12.2/ / / enter the extracted nginx file directory [root@nginx nginx-1.12.2] #. / configure\ / / configure nginx >-- prefix=/usr/local/nginx\ >-- user=nginx\ >-- group=nginx\ >-- with-http_stub_status_module...// omits some of the contents. Nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_ temp [root @ nginx nginx-1.12.2] # make & & make install / / production and installation nginx...// omitted part of the content. Test-d'/ usr/local/nginx/html'\ | | cp-R html' / usr/local/nginx'test-d'/ usr/local/nginx/logs '\ | | mkdir-p' / usr/local/nginx/logs'make [1]: leave the directory "/ opt/nginx-1.12.2" [root@nginx nginx-1.12.2] # ln-s / usr/local/nginx/sbin/* / usr/local/sbin/ create a soft connection file to the system command directory [root@nginx nginx-1.12.2] # cd / lib/systemd/system / / enter the system tube Manage directory [root@nginx system] # vim nginx.service / / Edit nginx startup script file [Unit] Description=nginxAfter= network.target [Service] Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/bin/kill-s HUP $MAINPIDExecStop=/usr/bin/kill-s QUIT $MAINPIDPrivateTmp= true [install] WantedBy=multi-user.target:wq [root@nginx system] # chmod 754 nginx.service / / add execution permissions [root@nginx system ] # systemctl start nginx.service / / start the service [root@nginx system] # systemctl stop firewalld.service / / turn off the firewall [root@nginx system] # setenforce 0 / / disable the enhanced security feature
Test the Nginx service on the client
Configure static and dynamic separation
Enable the function in the nginx service configuration file, and transfer the dynamic access to the LAMP host for processing, so as to achieve static and dynamic separation.
[root@nginx system] # vim / usr/local/nginx/conf/nginx.conf...// omits part of the content. Error_page 500 502 503 504 / 50x.htl; location = / 50x.html {root html } # proxy the PHP scripts to Apache listening on 127.0.0.1 location 80 # location ~\. Php$ {/ / Open this module and change the IP address to the host of LAMP, that is, the host that hands the dynamic request to the host of LAMP to handle the proxy_pass http://192.168.144.137; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1 root html;...// 9000 # # location ~\. Php$ {# root html;...// omitted part of the content: wq [root@nginx system] # systemctl stop nginx.service / / shut down the service [root@nginx system] # systemctl start nginx.service / / restart the service
Test whether the separation of movement and movement is successful at the customer
At this point, the study on "how to build Nginx dynamic and static separation in Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.