worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
rewrite ^/([0-9]+).html$ /index.jsp?pageNum=$1 break;
proxy_pass http://192.168.159.104;
}
#location 使用正则匹配
#css|fonts|img|js的文件目录
location ~*/(css|fonts|img|js) {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
总结 rewrite 可以按照规则 伪装url地址 并转发到目标网站
rewrite是实现URL重写的关键指令,根据regex (正则表达式)部分内容,重定向到replacement,结尾是flag标记。
同时使用负载均衡
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream httpds{
server 192.168.159.102 weight=1;
server 192.168.159.103 weight=3;
server 192.168.159.104 weight=2;
server 192.168.159.105 weight=6;
}
server {
listen 80;
server_name localhost;
location / {
rewrite ^/([0-9]+).html$ /index.php?pageNum=$1 break;
proxy_pass http://httpds;
}
#location 使用正则匹配
#css|fonts|img|js的文件目录
location ~*/(css|fonts|img|js) {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
配置完成了
- 动静分离
- UrlRewrite
- 网关服务器
- 反向代理服务器
- 负载均衡服务器