Welcome! Log In Create A New Profile

Advanced

Re: Override Content-Type header with proxied requests

August 07, 2014 01:58PM
Did you tried to only hide the header with
proxy_hide_header Content-Type;
and let nginx use the mime.types to set the content type?

Do not set the add_header Content-Type manually.

Let me know the result.


On Thu, Aug 7, 2014 at 12:57 PM, manish-ezest <nginx-forum@nginx.us> wrote:

> Hello wandenberg,
>
> Thank you for your response. I truly appreciate your help. I tried this
> options given below
>
> ######First Method###############
> 1. Edit nginx.conf and add
> map $uri $custom_content_type {
> default "text/html";
> ~(.*\.json)$ "application/json";
> }
>
> 2. Put the custom map in location directive
> 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 Pragma "no-cache";
> proxy_cache_valid 200 302 10m;
> proxy_read_timeout 60s;
> proxy_hide_header Content-Type;
> add_header Content-Type $custom_content_type;
> }
>
> ######Second Method###############
> 1. Edit nginx.conf and add
> map $uri $custom_content_type {
> default "text/html";
> ~(.*\.json)$ "application/json";
> }
>
> 2. Put the custom map in location directive
> 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 Pragma "no-cache";
> proxy_cache_valid 200 302 10m;
> proxy_read_timeout 60s;
> location ~ \.json$ {
> proxy_hide_header Content-Type;
> add_header Content-Type $custom_content_type;
> }
> }
>
> ##Third Method####################
>
> 1. Enter this in server block of nginx.
> location ~ \.json$ {
> types { }
> default_type application/json;
> }
>
> #################################
>
> 1. When I tried first method I put below content in "location / { }" and
> due
> to this the JSON file served as application/json but all other files loaded
> as text/html as it was default in the map directive which caused image/css
> to not load. I thought it would read the mime.types files and will select
> the appropriate Content-Type.
> #########################
> proxy_hide_header Content-Type;
> add_header Content-Type $custom_content_type;
> ##########################
>
> 2. When I tried second and third method, I am getting 404 because it is
> taking docroot as /var/empty
>
> 2014/08/07 17:13:22 [error] 14205#0: *33 open()
> "/var/empty/aaa/bbb/ccc/ddd/eee.json" failed (2: No such file or
> directory),
> client: 5.5.5.5., server: www-aaa.com, request: "GET
> /aaa/bbb/ccc/ddd/eee.json HTTP/1.1", host: "www.aaa.coml"
>
> So my question is where should I put the location ~\.json block(in location
> / {} or in server directive)?
>
> **************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
> combined_time;
> 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_pass 127.0.0.1:8999;
> 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/;
> }
> }
> ***************************************************************************
>
> NOTE: All my files are served from s3 bucket and not a single files are in
> the server.
>
> --Manish
>
> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?2,239473,252390#msg-252390
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Override Content-Type header with proxied requests

andrea.mandolo May 23, 2013 11:07AM

Re: Override Content-Type header with proxied requests

Jonathan Matthews May 23, 2013 11:12AM

Re: Override Content-Type header with proxied requests

António P. P. Almeida May 23, 2013 11:26AM

Re: Override Content-Type header with proxied requests

António P. P. Almeida May 23, 2013 11:34AM

Re: Override Content-Type header with proxied requests

manish-ezest August 06, 2014 08:18AM

Re: Override Content-Type header with proxied requests

andrea.mandolo May 24, 2013 04:58AM

Re: Override Content-Type header with proxied requests

wandenberg August 07, 2014 12:12AM

Re: Override Content-Type header with proxied requests

manish-ezest August 07, 2014 11:57AM

Re: Override Content-Type header with proxied requests

wandenberg August 07, 2014 01:58PM

Re: Override Content-Type header with proxied requests

manish-ezest August 07, 2014 02:17PM

Re: Override Content-Type header with proxied requests

manish-ezest August 07, 2014 02:30PM

Re: Override Content-Type header with proxied requests

manish-ezest August 08, 2014 09:23AM

Re: Override Content-Type header with proxied requests

wandenberg August 08, 2014 11:44AM

Re: Override Content-Type header with proxied requests

manish-ezest August 08, 2014 10:34PM

Re: Override Content-Type header with proxied requests

manish-ezest August 13, 2014 06:18AM

Re: Override Content-Type header with proxied requests

flygoast August 09, 2014 11:36PM

Re: Override Content-Type header with proxied requests

Pavel Vasev May 24, 2015 07:26AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 307
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready