1.nginx.conf
worker_processes 1; //开启进程
events {
worker_connections 1024; //每个进程的连接数
}
http {
include mime.types; //访问页面的类型
default_type application/octet-stream;
sendfile on; // 开启后,网络接口可以直接读取网页文件;关闭需要nginx读取发送给网络接口
upstream 集群名字 {
//负载均衡配置 服务器资源
server ip:port weight;
server ip:port weight;
}
server {
listen 80;
server_name localhost; //域名、主机名 可以使用多个
//代理
location / {
root html;//root目录 html目录下去找网页文件
index index.html index.htm; //默认页
//rewrite ^/2.html$ /index.jsp?*** break;
// proxy_pass http://集群名字;
// proxy_pass http://www.xxxx.com; 可以 单独代理
}
location ~*/(js|css|img) { //正则匹配
//valid_referers 192.168.1.1; #防盗链 允许192.168.1.1·
//if ($invalid_referer) {
// return 403;
}
root html;
index index.html index.htm;
}
location /admin {
// xxxx
}
error_page 500 502 503 504 /50x.html;//错误页面跳转
location = /50x.html{
root html;
}
}
server {
listen 443;
server_name localhost;
//代理
}
}
2.rewrite地址重定向
location / {
root html;//root目录 html目录下去找网页文件
index index.html index.htm; //默认页
rewrite ^/2.html$ /index.jsp?*** break;
#rewrite ^/([0-9]+).html$ /index.jsp?page=$1 break;#参数匹配跳转
#rewrite 假地址 真实地址 last|break|redirect|permanent;
#last:继续向下匹配
#break:停止匹配
#redirect:临时重定向 302
#permanent:永久重定向 301
// proxy_pass http://集群名字;
// proxy_pass http://www.xxxx.com; 可以 单独代理
}
3.防盗链配置
valid_referers 192.168.1.1; #防盗链 允许192.168.1.1·
#valid_referers none|blocked|server_names|strings;
#none: 代理引用访问不行 可以直接访问
if ($invalid_referer) {
//return 403;
rewrite ^/ /img/x.png break;
}