Nginx Series-8. Configure Nginx+apache to achieve static and dynamic separation directory-Nginx series
Nginx Series -1.linux Installation Nginx
Nginx Series-2. Configuring the Lnmp (Linux, Nginx, MySQL, PHP) architecture
Nginx Series-3. Configuring Nginx Virtual Host
Nginx Series -4.nginx log configuration and log cutting
Nginx Series-5. Configure the Nginx anti-theft chain
Nginx Series-6. Configuring Nginx HTTPS
Nginx Series-7. Configuring Nginx using UWSGI support web.py framework
Nginx Series-8. Configuration nginx+apache for dynamic and static separation
Nginx Series-9. Configuring NFS for static and dynamic separation of Nginx
Nginx Series-10. Using Nginx to build forward proxy service
Nginx Series-11. Configuring Nginx Reverse proxy and load balancing
Experimental Environment
Two minimized CentOS 7.3 virtual machines
server1-ip:192.168.204.133
server2-ip:192.168.204.134
Experimental topology
First, Server1 installation configuration Nginx
-
Install nginx
yum install-y epel-*yum install-y nginx vim
-
Establish nginx
home directory and home page
mkdir/var/ Wwwrootcd/var/wwwrootecho-e "Nginx" >> nginx.html
-
Configure nginx
configuration file
vim/etc/nginx/nginx.conf
Modify the default server
block as follows
server {listen 80;server_name _;location/{root/var/wwwroot; Index index.html index.htm;} Location ~ \.php$ {proxy_pass http://[apache ' s IP address]; #修改为Apache的IP地址 proxy_set_header host $host;}}
-
Restart nginx
service
systemctl restart Nginx
- Close firewall
setenforce 0systemctl stop Firewalldsystemctl Disable FIREWALLD
Second, server2 installation configuration Apache and PHP
Installation Apache
andPHP
yum install -y httpd php
Apache
Create a PHP file in the Web root directory ( /var/www/html
)
cd /var/www/htmlecho -e "<?php phpinfo(); ?>" >> info.php
Restart Apache
Service
systemctl restart httpd
- Shutting down the firewall
setenforce 0systemctl stop firewalldsystemctl disable firewalld
Three, the test static and dynamic separation, host access server1
Access http://192.168.204.133/nginx.html
Returned is the server1
resource on the
- Visit PHP page
http://192.168.204.133/info.php
Returned is the server2
resource on the
Nginx Series-8. Configuration nginx+apache for dynamic and static separation