How to deploy Nginx+Apache and separate dynamic and static
nginx动静分离介绍
nginx的静态处理能力很强,但是动态处理能力不足,因此,在企业中常用动静分离技术
针对php的动静分离
静态页面交给nginx处理
动态页面交给php-fpm模块或apache处理
在nginx的配置中,是通过location配置段配合正则匹配实现静态与动态页面的不同处理方式
反向代理原理
nginx不仅能作为web服务器,还具有反向代理、负载均衡和缓存的功能
nginx通过proxy模块实现将客户端的请求代理至上游服务器,此时nginx与上游服务器的连接是通过http协议进行的
nginx在实现反向代理功能时的最重要指令为proxy_ pass,它能够并能够根据uri、客户端参数或其它的处理逻辑将用户请求调度至上游服务器
配置nginx实现动静分离
本案例根据企业需要,将配置nginx实现动静分离,对php页面的请求转发给lamp处理,而静态页面交给nginx处理,以实现动静分离
架构如图所示
配置步骤
1、架设并调试后端lamp环境
①安装apache服务
[root@localhost ~]# yum install httpd httpd-devel -y
②在防火墙设置http服务的权限
1 2 3 4 5 6 7 |
|
③安装mariadb
mariadb数据库管理系统是mysql的一个分支,主要由开源社区在维护,采用gpl授权许可 mariadb的目的是完全兼容mysql,包括api和命令行,使之能轻松成为mysql的代替品
1 2 |
|
④mysql安全配置向导
1 |
|
⑤安装php及支持的软件
1 2 3 |
|
⑥更改网页主页面
1 2 3 4 5 6 7 |
|
⑦访问测试,输入网址
2、编译安装nginx
①安装支持软件
1 |
|
②创建运行用户和组
1 |
|
③编译安装
1 2 3 4 5 6 7 8 9 10 |
|
④服务管理控制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
⑤启动服务
1 2 3 |
|
⑥配置nginx处理动态页面请求
1 2 3 4 5 6 |
|
⑦访问测试
The above is the detailed content of How to deploy Nginx+Apache and separate dynamic and static. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Deploying a ZooKeeper cluster on a CentOS system requires the following steps: The environment is ready to install the Java runtime environment: Use the following command to install the Java 8 development kit: sudoyumininstalljava-1.8.0-openjdk-devel Download ZooKeeper: Download the version for CentOS (such as ZooKeeper3.8.x) from the official ApacheZooKeeper website. Use the wget command to download and replace zookeeper-3.8.x with the actual version number: wgethttps://downloads.apache.or

There are many ways to solve CentOS system failures. Here are some common steps and techniques: 1. Check the log file /var/log/messages: system log, which contains various system events. /var/log/secure: Security-related logs, such as SSH login attempts. /var/log/httpd/error_log: If you use the Apache server, there will be an error message here. 2. Use the diagnostic tool dmesg: display the contents of the kernel ring buffer, which helps understand hardware and driver questions
