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資源也越多,建議設(shè)置在5左右。
gzip_comp_level 5;
#需要壓縮哪些響應(yīng)類型的資源,多個空格隔開。不建議壓縮圖片.
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”響應(yīng)頭
#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'; #服務(wù)器允許將 cookie(或其他用戶憑據(jù))包含在跨域請求中.
add_header Content-Type "application/pdf"; #文檔類型
add_header Content-Disposition "inline"; #規(guī)定瀏覽器用內(nèi)聯(lián)方法打開還是直接下載
}
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以某個常規(guī)字符串開頭,理解為匹配url路徑即可,nginx不對url做編碼,因此請求為/static/20%/aa,可以被規(guī)則 ^$ /static/ /aa 匹配到