Nginx动态静态请求的分离
Nginx动态静态请求的分离通过conf配置文件实现.
Nginx 配置文件(来自菜鸟教程):
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
可以配置不同的location匹配规则,将请求转发到不同的服务器.
例如:
location ~ .php$ {
proxy_pass http://127.0.0.1;
}
location ~ .(jsp|do)$ {
proxy_pass http://127.0.0.2;
}
location ~ .(jpg|png|gif)$ {
proxy_pass http://127.0.0.3;
}
.php的请求,转发到127.0.0.1去处理
.jsp,.do的请求,转发到127.0.0.2去处理
.jpg,.png,.gif的请求,抓发到127.0.0.3去处理