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

Separation of static and dynamic processing by Nginx

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

Share

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

What this article shares to you is the method of Nginx to realize the separation of movement and movement. I believe that most people have not yet learned this skill. In order to let you learn, I have summarized the following content for you. Without saying much, let's read on.

Introduction to the static and static separation of Nginx the static processing capacity of Nginx is very strong, but the dynamic processing capacity is insufficient, so the static and static separation technology is commonly used in enterprises to deal with the static and dynamic separation of 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 by location configuration segment with regular matching. Reverse proxy principle Nginx can not only act as a web server, but also have reverse proxy, load balancing and caching functions Nginx proxies client requests to upstream servers through proxy module At this time, the connection between Nginx and upstream server is carried out through http protocol. When Nginx implements the reverse proxy function, the most important instruction is proxy_pass, which can schedule user requests to upstream server experimental environment LAMP server (192.168.13.139) Nginx server (192.168.13.140) 1 according to URI, client parameters or other processing logic, build LAMP (simple build) 1, and install Apache service. And allow access through the firewall [root@lamp ~] # yum install httpd httpd-devel-y # # install http service and development package [root@lamp ~] # systemctl start httpd.service # # enable service [root@lamp ~] # firewall-cmd-- permanent-- zone=public-- add-service=http # # firewall allows httpsuccess [root@lamp ~] # firewall-cmd-- permanent-- zone=public-- add-service=httpssuccess [root@lamp ~] # firewall-cmd-- reload # # restart firewall success2 Install the mariadb database [root@lamp ~] # yum install mariadb mariadb-server mariadb-libs mariadb-devel-ntap # install the database [root@lamp ~] # systemctl start mariadb # # Open the database [root@lamp ~] # netstat-ntap | grep 3306 # # View the port number 3306tcp 00 0.0.0.0 root@lamp 3306 0.0.0.0 LISTEN 2200/mysqld [root@lamp ~] # mysql_secure_ Installation # # set database Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [root] y # # set root password New password: # # enter password Re-enter new password: # # confirm password Remove anonymous users? [YBO] n # # allows anonymous access... Skipping.Disallow root login remotely? [YBO] n # # allows remote login. Skipping.Remove test database and access to it? [YBO] n # # keep the test database. Skipping.Reload privilege tables now? [YBO] y # # restart the database. Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDBMS 3, install PHP And database association [root@lamp ~] # yum install php- y # # install PHP [root @ lamp ~] # yum install php-mysql-y # # establish php and mysql association [root@lamp ~] # yum install-y\ > php-gd # # GD library is an extension of php processing graphics > php-ldap # # lightweight Directory access Protocol > php-odbc # # API > php-pear # # extended Application Code Base > php-xml php-xmlrpc # # xml File > php-mbstring # # multibyte string > php-snmp # # Management Development > php-soap # # SOAP extension can be used to provide and use Web Services > curl curl-devel # # support data file download tool > php-bcmath # # BCMath library to support more accurate calculation 4 Switch to the site, edit the page content [root@lamp] # cd / var/www/html/ # # switch to the site [root@lamp html] # vim index.php # # Edit the php page content 5, and test the page

[root@lamp html] # vim index.php # # Edit php page content

Second, install Nginx1 Use remote sharing on Linux to obtain files and mount them to the mnt directory [root@localhost ~] # smbclient-L / / 192.168.100.3 / # # remote share access Enter SAMBA\ root's password: Sharename Type Comment -LNMP-C7 Disk [root@localhost ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / mnt # # Mount to / mnt directory 2 Decompress the source code package to / opt And view [root@localhost ~] # cd / mnt # # switch to the mount point directory [root@localhost mnt] # lsDiscuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gzmysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz [root@localhost mnt] # tar zxvf nginx-1.12.2.tar.gz-C / opt # # decompress the Nginx source code package to / opt [root@localhost mnt ] # cd / opt/ # # switch to [root@localhost opt] # lsnginx-1.12.2 rh3 under the decompressed directory Install the environment component package required for compilation [root@localhost opt] # yum-y install\ gcc\ / c language gcc-c++\ / / C++ language pcre-devel\ / / pcre language tool zlib-devel / / function library for data compression 4 Create program user nginx and compile Nginx [root@localhost opt] # useradd-M-s / sbin/nologin nginx # # create program user Security non-login status [root@localhost opt] # id nginxuid=1001 (nginx) gid=1001 (nginx) group = 1001 (nginx) [root@localhost opt] # cd nginx-1.12.0/ # # switch to the nginx directory [root@localhost nginx-1.12.0]. / configure\ # # configure nginx >-- prefix=/usr/local/nginx\ # # installation path >-- user=nginx\ # # user name >-- group=nginx\ # # user group >-- with-http_stub_status_module # # status statistics module 5 Compile and install [root@localhost nginx-1.12.0] # make # # compile. [root@localhost nginx-1.12.0] # make install # # install. [root@localhost nginx] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # # create a soft connection to let the system recognize nginx startup script 6 and make a management script Easy to use service management to use [root@localhost nginx] # cd / etc/init.d/ # # to switch to the startup configuration file directory [root@localhost init.d] # lsfunctions netconsole network README [root@localhost init.d] # vim nginx # # Edit the startup script file #! / bin/bash# chkconfig:-99 20 # # comment Information # description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" # # set the variable to the nginx command file PIDF= "/ usr/local/nginx/logs/nginx.pid" # # set the variable PID file process number is 5346case "$1" in start) $PROG # # start the service ; stop) kill-s QUIT $(cat $PIDF) # # disable the service;; restart) # # restart the service $0 stop $0 start Reload) # # reload service kill-s HUP $(cat $PIDF) *) # # incorrect input prompt echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit 0 [root@localhost init.d] # chmod + x / etc/init.d/nginx # # give startup script execution permission [root@localhost init.d] # chkconfig-- add nginx # # add to service Manager [root@localhost init.d] # service nginx stop # # you can use service to control nginx [root@localhost init.d] # service nginx start7 Install elinks test Nginx web page [root@localhost init.d] # yum install elink-y # # install software [root@localhost init.d] # netstat-ntap | grep 80 # # View Nginx port tcp 0 0 0.0 0 LISTEN 44663/nginx: master [root@localhost init.d] # systemctl stop firewalld.service # # turn off firewall [root@localhost init.d] # setenforce 0 [ Root@localhost init.d] # elinks http://192.168.13.140/ # # testing web pages

8, visit the Nginx web page

Third, modify Nginx configuration file to enable static and dynamic separation [root@localhost init.d] # vim / usr/local/nginx/conf/nginx.conf # # modify configuration file location ~\ .php$ {# # find here to remove comments and enable static and dynamic separation proxy_pass http://192.168.13.139; # # fill in the server address of dynamically processed Apache} [root@localhost init.d] # service nginx stop # # close [root@localhost init.d] # service nginx start # # Open four, test the web page (192.168.13.140)

After reading the above, have you mastered the method of static and dynamic separation by Nginx? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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