Override Content-Type header with proxied requests

manish-ezest nginx-forum at nginx.us
Sat Aug 9 02:34:06 UTC 2014

Hello Wandenberg,

Yes, the back-end(s3 bucket) is sending Content-Type header for each request
and what I heard from the developers that the header is must for the site to
work properly. 

The issue started when I got the request of enabling content-type header of
all the json files to application/json. As the default content-type in NGINX
is application/octet-stream, the JSON files are served as
application/octet-stream. The jquery uses content-type header to identify
the JSOn files and due to the application/octet-stream content type it is
not able to identify the JSOn files.

I tried many options but each time one of the features(html files got
downloaded, CSS not loaded, CSS problem in internet explorer) got impacted.

I will try adding all the mime types to the map directive and will let you
know the result.

Here is my nginx.conf and vhost file for your reference

**************my NGINX.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 main '$remote_addr - $remote_user [$time_local] $request '
 '"$status" $body_bytes_sent "$http_referer" '
 '"$http_user_agent" "$http_x_forwarded_for"';
 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;
 include /etc/nginx/servers/*.conf;

 ******************************VHOST SETTING*****
 server {
 listen 80;
 server_name www-aaa.com;
 add_header Cache-Control off;
 expires 1d;
 root /var/empty;
 error_log /var/log/nginx/www.aaa.com-error.log;
 access_log /var/log/nginx/www.aaa.com-access.log
 location = /favicon.ico {
 root /www;
 proxy_intercept_errors on;
 error_page 400 401 402 403 404 406 407 408 409 410 411 412 413 414 415 416
 417 495 496 497 500 501 502 503 504 505 506 507 = /error_page.pl;
 error_page 405 =200 $uri;
 location /error_page.pl {
 fastcgi_param REQUEST_URI $request_uri;
 fastcgi_pass_header "Status";

 location / {
 proxy_redirect off;
 proxy_set_header Host www.aaa.com.s3.amazonaws.com;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Referer www.aaa.com;
 proxy_pass http://www.aaa.com.s3.amazonaws.com/;
 add_header         Access-Control-Allow-Origin *;

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,239473,252439#msg-252439

More information about the nginx mailing list