2

My server is serving my "manifest.json" file as text/plain which means the browser can't read it.

There is definitely a line for it in /etc/nginx/config/mime.types

application/json                      json;

But I can see in chrome dev tools that the type is wrong:

https://i.imgur.com/ClaTBS8.png

OS: Ubuntu 16.04.6

NGINX: 1.13.1

/etc/nginx/config/nginx.conf:

#+----------------------------------------------------------------------------+
#+ NGINX Configuration v1.0.0
#+----------------------------------------------------------------------------+
pcre_jit                                                on;

timer_resolution 100ms;
user nginx nginx;

worker_priority -10;
worker_processes 1;
worker_rlimit_nofile 260000;

events {
    accept_mutex off;
    accept_mutex_delay 200ms;
    use epoll;
    worker_connections 10000;
}


http {
    #+------------------------------------------------------------------------+
    #+ Enable Brotli
    #+------------------------------------------------------------------------+
    brotli on;
    brotli_static on;
    brotli_min_length 1000;
    brotli_buffers 32 8k;
    brotli_comp_level 5;
    brotli_types *;

    #+------------------------------------------------------------------------+
    #+ client_max_body_size controls the maximum file upload size - this will
    #+ need to be modified should you need to allow file uploads over 50MB.
    #+------------------------------------------------------------------------+
    client_body_buffer_size 256k;
    client_body_in_file_only off;
    client_body_timeout 10s;
    client_header_buffer_size 64k;
    client_header_timeout 5s;
    client_max_body_size 50m;

    charset utf-8;
    connection_pool_size 512;
    default_type application/octet-stream;
    directio 4m;

    #+------------------------------------------------------------------------+
    #+ Enable GZIP
    #+------------------------------------------------------------------------+
    gzip on;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    gzip_static on;
    gzip_min_length 1400;
    gzip_buffers 32 8k;
    gzip_http_version 1.0;
    gzip_comp_level 5;
    gzip_proxied any;
    gzip_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml;

    ignore_invalid_headers on;
    include /etc/nginx/config/mime.types;
    index index.php index.html;

    keepalive_disable msie6;
    keepalive_requests 500;
    keepalive_timeout 5;

    large_client_header_buffers 8 64k;
    lingering_time 20s;
    lingering_timeout 5s;

    map_hash_bucket_size 128;
    map_hash_max_size 4096;

    open_file_cache max=50000 inactive=60s;
    open_file_cache_errors off;
    open_file_cache_min_uses 2;
    open_file_cache_valid 120s;
    open_log_file_cache max=10000 inactive=30s min_uses=2;

    output_buffers 8 256k;
    postpone_output 1460;

    proxy_temp_path /etc/nginx/cache/proxy;

    request_pool_size 32k;
    reset_timedout_connection on;
    sendfile on;
    sendfile_max_chunk 512k;
    send_timeout 10s;

    server_names_hash_bucket_size 128;
    server_names_hash_max_size 2048;
    server_name_in_redirect off;

    server_tokens off;

    tcp_nodelay on;
    tcp_nopush on;

    types_hash_max_size 2048;
    variables_hash_max_size 2048;

    include /etc/nginx/sites/*.conf;
}

/etc/nginx/config/sites/headers.conf

add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";

/etc/nginx/sites/_.conf

server
{
    listen 80 default_server;
    listen [::]:80;
    server_name _;

    root /home/nginx/htdocs/public;

    location /
    {
        try_files $uri $uri/ =404;
    }
}

/etc/nginx/sites/example.com.conf

upstream example {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    return 301 https://$host$request_uri;
}

server
{
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;

    include /etc/nginx/config/sites/headers.conf;

    include /etc/nginx/config/ssl/resolver.conf;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    include /etc/nginx/config/ssl/ssl.conf;

    location /
    {
        proxy_pass http://example;

        include /etc/nginx/config/proxy/proxy.conf;
    }

    #include /etc/nginx/config/cache/static.conf;
}
stackers
  • 277
  • 1
  • 3
  • 13

2 Answers2

3

I added the following block to /etc/nginx/sites/example.com.conf

location ~ \.json {
    add_header  Content-Type    application/json;
    proxy_pass http://lospec;

    include /etc/nginx/config/proxy/proxy.conf;
}

and it seems to be working. But let me know if there's something wrong with doing it this way.

stackers
  • 277
  • 1
  • 3
  • 13
0

There can be possibility that the mime.types file is not being included in the nginx config and thus not getting loaded.

Can you please check if you have a line something like below in your main nginx.conf file. The path of nginx.conf might be /etc/nginx/nginx.conf or /etc/nginx/config/nginx.conf

include /etc/nginx/config/mime.types;

Samit
  • 121
  • 4
  • I have "/etc/nginx/config/nginx.conf" and there is a line for "include /etc/nginx/config/mime.types;" under http {} – stackers Nov 20 '19 at 20:03
  • Check this once and see if any of the answers can help in your case. https://stackoverflow.com/questions/29573489/nginx-failing-to-load-css-and-js-files-mime-type-error/54384884 – Samit Nov 20 '19 at 20:13