In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-06-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Setting up Nginx dynamic and static separation Nginx static and static separation introduction Nginx's static processing capacity is very strong, but dynamic processing capacity is insufficient, therefore, static and static 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 to handle. In the configuration of Nginx, different processing methods of static and dynamic pages are realized through location configuration segment and regular matching. Reverse proxy principle Nginx not only acts as a Web server, but also has the functions of reverse proxy, load balancing and caching. Nginx proxies client requests to upstream servers through the proxy module, nginx and. Upstream server connection is the most important instruction for Nginx to implement reverse proxy function through http protocol. It can and can schedule user requests to upstream server configuration according to URI, client parameters or other processing logic, and debug back-end LAMP environment installation configuration Nginx to handle static page requests. In server {} Add [root@nginx php5] # vim / usr/local/httpd/conf/nginx.conf location ~. *\. (gifiglipeglbmp | swf) ${root html; index index.html index.htm;} in the section; configure Nginx to handle dynamic page requests, and add Apache in server {};. Create a new test.php in the working directory and 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 of all, set up the lamp architecture in a Linux system, here use yum 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 to access the httpd service on the client Check whether the service is started successfully.
Install mariadb (mariadb is a branch of MySQL with the same function as MySQL) [root@localhost ~] # yum install mariadb mariadb-server mariadb-libs mariadb-devel-y loaded 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 setup installation PHP [root @ localhost ~] # yum-y install php / / install 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 web content: wq [root@localhost html] # systemctl restart httpd.service / / restart the http service to test whether the LAMP institution 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 ~] # / successfully [root@nginx nginx-1.12.2] # yum install gcc gcc-c++ make pcre-devel zlib-devel-y / / the plug-in has been loaded in the installation environment package: 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 to test the Nginx service on the client
Configure static and dynamic separation to enable the function in the nginx service configuration file and transfer 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...// omitting 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 . / / omit 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 to test whether the separation is successful
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.