我们的web项目在nginx上做了一次动静分离,在nginx上的配置:
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /data/vangogh/;
expires 1d; #使用expires缓存模块,缓存到客户端30天
}
### refuse illegal access
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
### speed limit
#limit_req zone=java burst=50 nodelay;
### include sub config file
#include sub.d/*.conf;
## web application root context for common iface2 service, featured location please specified in sub.d directory
location / {
proxy_pass http://local_worker;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
有一次,我们把druid引入到系统中,配置了sql的监控页面,这时访问druid的页面会出现404,原因是nginx上配置的静态资源请求都从nginx上获取,不用转发到后端服务器。而druid的页面都是封装到jar包中的,我们无法单独获取静态资源放到nginx服务器上。所以,我们需要在nginx上多加一个配置,对于druid的请求,都转发到后端。
location ~ /druid/.*\.(html|htm|woff|ttf|svg|eot|gif|jpg|jpeg|bmp|png|ico|txt|js|css|xml)$ {
proxy_pass http://local_worker;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /data/vangogh/;
expires 1d; #使用expires缓存模块,缓存到客户端30天
}
### refuse illegal access
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
### speed limit
#limit_req zone=java burst=50 nodelay;
### include sub config file
#include sub.d/*.conf;
## web application root context for common iface2 service, featured location please specified in sub.d directory
location / {
proxy_pass http://local_worker;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
}