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

Nginx and Apache dynamic and static separate deployment

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 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

● 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.

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.

Nginx dynamic and static separation examples demonstrate 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.

Service item IP address LAMP schema 192.168.235.137Nginx192.168.235.1581, Set up and configure LAMP environment yum install httpd httpd-devel-yearly # use yum installation architecture systemctl start httpd.service## launch 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 to firewall public area Success [root@localhost ~] # firewall-cmd-- reload # # reload Firewall success [root@localhost ~] # yum install mariadb mariadb-server mariadb-libs mariadb-devel-MYSQL # install the 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 to access the Apache page of 192.168.235.137/index.php

[root@localhost ~] # cd / var/www/html [root@localhost html] # vim index.php## modifies the output of web pages II. The first step in installing and configuring the Nginx service: use remote sharing on Linux to obtain the source code package from Windows share [root@localhost ~] # smbclient-L / / 192.168.235.1 / # # remote shared 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 step 2: compile and install Nginx1 Extract the source code package to the / opt directory [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 / Under opt, [root@localhost abc] # cd / opt/ # # switch to [root@localhost opt] # lsnginx-1.12.2 rh2 under the decompressed directory Install the environment component package [root@localhost opt] # yum-y install\ gcc\ / c language gcc-c++\ / / C++ language pcre-devel\ / / pcre language tool zlib-devel / / data compression function library 3 Create program user nginx and compile Nginx [root@localhost opt] # useradd-M-s / sbin/nologin nginx # # create program 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 install5 Optimize the Nginx service startup script And set up a command soft link [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 LISTEN 39620/nginx: master [root@localhost nginx] # systemctl stop firewalld.service # # turn off the firewall [root@localhost nginx] # setenforce 0 [root@localhost nginx] # nginx # # enable nginx service 6 Systemctl Management nginx script [root@localhost ~] # vim / lib/systemd/system/nginx.service # # create profile [Unit] Description=nginx # # describe After=network.target # # describe service type [Service] Type=forking # # 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 # terminate the process PrivateTmp= true [install] WantedBy=multi-user.target [root according to PID @ localhost ~] # chmod 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 the 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 LAMP 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. Verify the effect of static and dynamic separation step 1: visit the Nginx static web page of 192.168.235.158/index.html step 2: visit the dynamic web page forwarded to LAMP by Nginx of 192.168.235.158/index.php

-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