L'activation de type de contenu application/json pour tous les fichiers json dans nginx

Actuellement, je suis confronté à un problème concernant l'activation de contenu-type de NGINX.
Vous pouvez voir ci-dessous dans nginx.conf que la valeur par défaut du type de contenu est application/octet-stream.

J'ai 5 de l'hôte virtuel configuré dans NGINX et je veux le servir tous les fichiers json avec le Type de Contenu application/json.

J'ai ajouté "application/json json;" dans le mime.type de fichiers et redémarré le service nginx, mais encore quand j'ai accès à tout fichier json, il est à venir par type de contenu application/octet-stream.

Est-il autre chose que je dois faire pour desservir le fichier JSON que l'application/json?

### curl -v http://www.ajay.com/abc/def/ghi/jkl/mno.json

* Hostname was NOT found in DNS cache
*   Trying xx.xx.xx.xx...
* Connected to www.ajay.com (xx.xx.xx.xx) port 80 (#0)
> GET abc/def/ghi/jkl/mno.json HTTP/1.1
> User-Agent: curl/7.36.0
> Host: www.ajay.com
> Accept: */*
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Cache-Control: max-age=86400
< **Content-Type: application/octet-stream**
< Date: Tue, 29 Jul 2014 17:03:53 GMT
< ETag: "ab9b7b2c58d3a481e172aea95b1e87a0"
< Expires: Wed, 30 Jul 2014 17:03:53 GMT
< Last-Modified: Fri, 25 Jul 2014 13:18:14 GMT
* Server nginx is not blacklisted
< Server: nginx
< Content-Length: 603
< Connection: keep-alive
.
.
.

[root@ajay nginx]# nginx -v
nginx version: nginx/1.4.3
[root@ajay nginx]# ls -lh mime.types
-rw-r--r-- 1 root root 3.5K Jul 29 10:36 mime.types

Mon mime.les types de fichier

[root@ajay nginx]# cat mime.types
types {
text/html                             html htm shtml;
text/css                              css;
text/xml                              xml;
image/gif                             gif;
image/jpeg                            jpeg jpg;
**application/json                      json;**
application/x-javascript              js;
application/atom+xml                  atom;
application/rss+xml                   rss;
text/mathml                           mml;
text/plain                            txt;
text/vnd.sun.j2me.app-descriptor      jad;
text/vnd.wap.wml                      wml;
text/x-component                      htc;
image/png                             png;
image/tiff                            tif tiff;
image/vnd.wap.wbmp                    wbmp;
image/x-icon                          ico;
image/x-jng                           jng;
image/x-ms-bmp                        bmp;
image/svg+xml                         svg svgz;
image/webp                            webp;
application/java-archive              jar war ear;
application/mac-binhex40              hqx;
application/msword                    doc;
application/pdf                       pdf;
application/postscript                ps eps ai;
application/rtf                       rtf;
application/vnd.ms-excel              xls;
application/vnd.ms-powerpoint         ppt;
application/vnd.wap.wmlc              wmlc;
application/vnd.google-earth.kml+xml  kml;
application/vnd.google-earth.kmz      kmz;
application/x-7z-compressed           7z;
application/x-cocoa                   cco;
application/x-java-archive-diff       jardiff;
application/x-java-jnlp-file          jnlp;
application/x-makeself                run;
application/x-perl                    pl pm;
application/x-pilot                   prc pdb;
application/x-rar-compressed          rar;
application/x-redhat-package-manager  rpm;
application/x-sea                     sea;
application/x-shockwave-flash         swf;
application/x-stuffit                 sit;
application/x-tcl                     tcl tk;
application/x-x509-ca-cert            der pem crt;
application/x-xpinstall               xpi;
application/xhtml+xml                 xhtml;
application/zip                       zip;
application/octet-stream              bin exe dll;
application/octet-stream              deb;
application/octet-stream              dmg;
application/octet-stream              eot;
application/octet-stream              iso img;
application/octet-stream              msi msp msm;
audio/midi                            mid midi kar;
audio/mpeg                            mp3;
audio/ogg                             ogg;
audio/x-m4a                           m4a;
audio/x-realaudio                     ra;
video/3gpp                            3gpp 3gp;
video/mp4                             mp4;
video/mpeg                            mpeg mpg;
video/quicktime                       mov;
video/webm                            webm;
video/x-flv                           flv;
video/x-m4v                           m4v;
video/x-mng                           mng;
video/x-ms-asf                        asx asf;
video/x-ms-wmv                        wmv;
video/x-msvideo                       avi;
}

Mon nginx.fichier conf

user              nginx;
worker_processes  1;
error_log         /var/log/nginx/error.log  notice;
pid               /var/run/nginx.pid;
worker_rlimit_nofile 30000;
events {
worker_connections  1024;
}
http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;
log_format combined_time '$remote_addr - $remote_user [$time_local]'
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" $request_time';
access_log  /var/log/nginx/access.log  combined_time;
## Size Limits
client_body_buffer_size      16k;
client_header_buffer_size     1k;
client_max_body_size         20k;
large_client_header_buffers 4 4k;
## Timeouts
client_body_timeout     5;
client_header_timeout   5;
keepalive_timeout     5 5;
send_timeout            5;
## General Options
ignore_invalid_headers   on;
keepalive_requests        2;
recursive_error_pages    on;
server_tokens           off;
server_name_in_redirect off;
sendfile                 on;
## TCP options
tcp_nopush  on;
tcp_nodelay on;
## Compression
gzip                 on;
gzip_static          on;
gzip_buffers      16 8k;
gzip_http_version   1.0;
gzip_comp_level       6;
gzip_min_length     100;
gzip_types          text/plain application/xml application/x-javascript  text/xml text/css image/x-icon image/gif image/jpeg;
gzip_vary            on;
gzip_disable        "MSIE [1-6]\.";
include /etc/nginx/conf.d/*.conf;
}

Merci de m'aider avec ce

  • Si vous voulez tous les fichiers JSON vous pouvez essayer le réglage de la default_type à application/json. Il n'explique pas pourquoi ce que vous avez fait n'est pas de travail. Avez-vous redémarrer Nginx, ou tout simplement recharger après ces changements? Aussi, est-il un fichier appelé /abc/def/ghi/jkl/mno.json ou est-ce une demande de la rédaction JSON? Si c'est une application, l'application peut avoir besoin de définir le type mime d'en-tête, au lieu de s'appuyer sur Nginx pour le faire.
InformationsquelleAutor user3847894 | 2014-07-29