In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
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
1. Static pages are handed over to Nginx for processing
2. Give the dynamic page 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.
Principle of Nginx reverse proxy
Nginx not only acts 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, where nginx and. The upstream server is connected through the http protocol. The most important instruction of Nginx in implementing reverse proxy function is proxy_ _ pass, which can and can schedule user requests to. Upstream server.
Real fuck
Requirements and Architecture:
According to the needs of the enterprise, the static and dynamic separation is realized by configuring Nginx, the request for the php page is forwarded to L AMP for processing, and the static page is handed over to Nginx for processing to achieve static and dynamic separation.
I. set up and configure the LAMP environment
Yum install httpd httpd-devel-yearly # use yum installation architecture systemctl start httpd.service## to start the service [root@localhost] # firewall-cmd-- permanent-- zone=public-- add-service=http # # add http protocol success [root@localhost] # firewall-cmd-- permanent-- zone=public-- add-service=https # # add https protocol success [root@localhost] # Firewall-cmd-- reload # # reload firewall success [root@localhost ~] # yum install mariadb mariadb-server mariadb-libs mariadb-devel-MYSQL # install MYSQL database using yum Mariadb database management system is a branch of MYSQL database [root@localhost ~] # systemctl start mariadb## startup database [root@localhost ~] # mysql_secure_installation # # set database Enter current password for root (enter for none): # # enter key Set root password? Enter the password New password: # # enter the password abc123Re-enter new password: # # re-confirm that the password is entered Remove anonymous users? Enter n to deny the removal of all anonymous users Disallow root login remotely? Enter n here to deny remote login to Remove test database and access to it using root identity? Enter n here to deny deleting the test database and accessing it Reload privilege tables now? Enter n here to determine the reload database [root@localhost ~] # yum-y install php## using yum install php [root @ localhost ~] # yum install php-mysql-y install # establish php and mysql association [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 the php plug-in [root@localhost ~] # cd / var/www/html## enter the site directory [root@localhost html] # vim index.php## edit the php page [root@localhost html] # systemctl restart httpd.service # # restart the service
2. Visit the Apache page of 192.168.235.137/index.php
[root@localhost ~] # cd / var/www/html [root@localhost html] # vim index.php## modify web page output 2. Install and configure Nginx service
1. Use remote sharing on Linux to obtain the source code package from Windows sharing
[root@localhost ~] # smbclient-L / / 192.168.235.1 / # # remote share access Enter SAMBA\ root's password: Sharename Type Comment-LNMP Disk [root@localhost ~] # mkdir / abc [root@localhost ~] # mount.cifs / / 192.168.235.1/LNMP / abc # # Mount to / abc directory
2. Decompress the source code package and install the environment component package needed for compilation
[root@localhost ~] # cd / abc # # switch to the mount point directory [root@localhost abc] # lsDiscuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gzmysql-boost-5.7.20.tar.gz php-7.1.10.tar.gz [root@localhost abc] # tar zxvf nginx-1.12.2.tar.gz-C / opt # # decompress the Nginx source code package to [root@localhost abc] # cd under / opt / opt/ # # switch to [root@localhost opt] # lsnginx-1.12.2 rh [root@localhost opt] # yum-y install\ gcc\ / c language gcc-c++\ / / C++ language pcre-devel\ / / pcre language tool zlib-devel under the extracted directory / / data compression function library
3. Create the program user nginx and compile Nginx
[root@localhost opt] # useradd-M-s / sbin/nologin nginx # # Creator user Limit its [root@localhost opt] # cd nginx-1.12.2/ # # switch to [root@localhost nginx-1.12.2] #. / configure\ # # configure nginx >-- prefix=/usr/local/nginx\ # # installation path >-- user=nginx\ # # user name >-- group=nginx\ # # user groups >-- with-http_stub_status_module # # access status Statistics Module
4. Compile and install
[root@localhost nginx-1.12.2] # make & & make install
5. Optimize the Nginx service startup script and establish command soft links
[root@localhost nginx] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # # create a soft connection to let the system recognize the nginx startup script [root@localhost nginx] # nginx-t # # check the syntax problems of the configuration file nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@localhost nginx] # nginx # # Open ngnix [root@localhost nginx] # netstat-ntap | grep 80 # # View port Nginx has enabled tcp 0 0 0.0.0.0 LISTEN 39620/nginx: master [root@localhost nginx] # systemctl stop firewalld.service # # turn off firewall [root@localhost nginx] # setenforce 0 [root@localhost nginx] # nginx # # enable nginx service
6. Systemctl manages nginx scripts
[root@localhost ~] # vim / lib/systemd/system/nginx.service # # create a profile [Unit] Description=nginx # # describe After=network.target # # describe the service type [Service] Type=forking # # background running form PIDFile=/usr/local/nginx/logs/nginx.pid # # PID file location ExecStart=/usr/local/nginx/sbin/nginx # # start the service ExecReload=/usr/bin/kill-s HUP $MAINPID # # configure ExecStop=/usr/bin/kill-s QUIT $MAINPID # # according to PID overload to terminate the process PrivateTmp= true [install] WantedBy=multi-user.target [root@localhost ~] # chmod according to PID 754 / lib/systemd/system/nginx.service # # set execution permission [root@localhost ~] # systemctl stop nginx.service # # close nginx [root@localhost ~] # systemctl start nginx.service # # enable
7. Modify Nginx.conf configuration file
[root@localhost ~] # vim / usr/local/nginx/conf/nginx.conf location ~\ .php$ {proxy_pass http://192.168.235.137; # # uncomment these three lines and point the address to the IP address of the Nginx service} [root@localhost ~] # systemctl stop nginx.service # # stop the service [root@localhost ~] # systemctl start nginx.service # # start the service [root@localhost ~] # systemctl stop firewalld.service # # turn off the firewall [root@localhost ~] # setenforce 0security # turn off the enhanced security function 3. Verify the effect of separation of movement and movement.
Visit 192.168.235.158/index.html 's Nginx static web page
Visit the dynamic web page forwarded to LAMP by 192.168.235.158/index.php 's Nginx
That is, it realizes the separate browsing of dynamic web pages and static web pages.
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.