worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
#低于1kb的资源不压缩
gzip_min_length 1k;
#压缩级别1-9,越大压缩率越高,同时消耗cpu资源也越多,建议设置在5左右。
gzip_comp_level 5;
#需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片.
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
#配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
gzip_disable "MSIE [1-6]\.";
gzip_vary on; #是否添加“Vary: Accept-Encoding”响应头
#gzip on;
server {
listen 8888;
server_name qqq;
# 参考文档 https://blog.csdn.net/m0_67403272/article/details/126113708
location /{
root D:\0prod;
index index.html index.htm;
}
location ^~/baidu/ {
proxy_pass http://www.baidu.com/;
}
location /e{
alias E:\0prod;
index index.html index.htm;
}
location /d{
alias D:\0prod;
index index.html index.htm;
}
location /pdf/{
proxy_pass http://pdf;
add_header Access-Control-Allow-Origin *; #允许任何来源的跨域请求
add_header Access-Control-Allow-Credentials 'true'; #服务器允许将 cookie(或其他用户凭据)包含在跨域请求中.
add_header Content-Type "application/pdf"; #文档类型
add_header Content-Disposition "inline"; #规定浏览器用内联方法打开还是直接下载
}
location /staticSpace{
alias E:\workspace\static;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials 'true';
add_header Content-Type "application/pdf";
add_header Content-Disposition "inline";
}
}
upstream pdf{
server 127.0.0.1:8001;
}
}
^~ 开头表示url以某个常规字符串开头,理解为匹配url路径即可,nginx不对url做编码,因此请求为/static/20%/aa,可以被规则 ^$ /static/ /aa 匹配到