如何解决 Nginx 使用反向代理时出现重复的 MIME 错误?

如何解决 Nginx 使用反向代理时出现重复的 MIME 错误?

我正在尝试使用反向代理从 blog.example.com 路由到 example.com/blog。

网站路由正常,但我遇到了图像无法显示的问题,并收到以下错误消息。

[warn] duplicate MIME type "text/html" in /etc/nginx/conf.d/example.conf

我在我的服务器块的 sub_filter_types 中收到 text/html 重复错误,但我找不到原因。

sub_filter_types text/html text/css text/xml text/javascript application/json;

有人能给我一些建议来解决这个问题吗?这是我正在使用的 nginx 设置。我删除了所有不必要的东西。

服务器块

map $upstream_http_location $_upstream_http_location_prefix { # 1
  default $upstream_http_location; # 2
  "~^/"                 "/blog";   # 3
  "~*^http"             "";        # 4
  "~*^((?!http|\/).)*"  "/blog/";  # 5
}

server {
    listen       80;
    server_name  example.com www.example.com;
    return       301 https://$server_name$request_uri;
}


server {
    listen       443 ssl http2;
    server_name  example.com www.example.com;
    root /var/www/example.com;
    index  index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;  
         add_header 'Access-Control-Allow-Origin' '*';
    }
        
        
    location /blog/wp-admin { return 301 /blog/404; }
    location /blog/wp-login.php { return 301 /blog/404; }

    # Prevent the blog's robots.txt from being proxied
    location /blog/robots.txt { return 404; }

 location /blog {
    rewrite /blog/(.*) /$1  break;
    rewrite ^([^.]*[^/])$ $1/ permanent;

    proxy_set_header Accept-Encoding "";

    sub_filter_once off;
    sub_filter_last_modified on;
    sub_filter_types text/html text/css text/xml text/javascript application/json;
    sub_filter 'blog.example.com' 'example.com/blog';

    sub_filter 'src="/wp-content/' 'src="/blog/wp-content/';
    
    proxy_hide_header Location;
    add_header Location "$_upstream_http_location_prefix$upstream_http_location";

    sub_filter 'http:' 'https:';

        proxy_pass https://blog.example.com;
   }


}

Nginx配置文件

#load_module modules/ngx_http_cache_purge_module.so;
user  www-data;
worker_processes  1;
include /etc/nginx/modules-enabled/*.conf;



error_log  /var/log/nginx/error.log crit;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 10000; 
events {
    worker_connections  1024;
    multi_accept off;
        use epoll;
    accept_mutex on;
}


http {
    charset           utf-8;

        server {
        charset        utf-8;
    }
        

    include /etc/nginx/blockips.conf;
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    # 새롭게 추가 6월 15일
    sendfile_max_chunk 512k;

    #DDOS 보안    
    # limit the number of connections per IP
    limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;

    # limit the number of requests for this session
    limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=10r/s;

    log_format custom '[$time_local] | $remote_addr | $status HTTP |'
                                '$http_x_forwarded_for(실제IP) | "$request" (방문주소)|'
                                '"$http_referer" | '
                                '"$http_user_agent"'; 


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log off;
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;
    server_tokens off;
    client_max_body_size 64m;
    add_header X-UA-Compatible "IE=Edge,chrome=1";


    client_body_timeout 14;
    client_header_timeout 14;
    keepalive_timeout 25;
    send_timeout 13;


    #gzip  on;
    #오픈파일캐쉬
    # 이걸로 다시 테스트
    open_file_cache max=3000 inactive=30s;
    open_file_cache_valid    60s;
    open_file_cache_min_uses 2;
    open_file_cache_errors   on;
    
    
    #open_file_cache max=1500 inactive=30s;
    #open_file_cache_valid 60s;
    #open_file_cache_min_uses 5;
    #open_file_cache_errors off; 
    
    
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    add_header Fastcgi-Cache $upstream_cache_status;
    
    fastcgi_cache_use_stale error timeout invalid_header http_500;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

    brotli on;
    brotli_comp_level 6;
    brotli_static on;
    brotli_types application/atom+xml application/javascript application/json application/rss+xml
       application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
       application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
       font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
       image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
       
    include /etc/nginx/conf.d/*.conf;
        
        
    
}

相关内容