headers-more-nginx-module icon indicating copy to clipboard operation
headers-more-nginx-module copied to clipboard

more_set_input_headers not working

Open ZTzha opened this issue 6 years ago • 6 comments

server { ... location / { ... more_set_input_headers 'myheader: test123'; .. } ... }

html-code: img src="http://x.x.x.x:xxxx/test/1.jpg"

it doesn't send request header to x.x.x.x?

ZTzha avatar Jan 15 '19 04:01 ZTzha

@ZTzha Please provide a minimal and self-contained example that we can run on our side and reproduce your problem. Your snippet above is incomplete and not runnable.

agentzh avatar Feb 04 '19 00:02 agentzh

@ZTzha BTW, make sure your image request indeed goes through your location /, not some other location configuration blocks. You can verify that by (temporarily) enabling the nginx debugging logs.

agentzh avatar Feb 04 '19 00:02 agentzh

I got the same problem.

my nginx.conf file

# nginx.conf  --  docker-openresty
#
# This file is installed to:
#   `/usr/local/openresty/nginx/conf/nginx.conf`
# and is the file loaded by nginx at startup,
# unless the user specifies otherwise.
#
# It tracks the upstream OpenResty's `nginx.conf`, but removes the `server`
# section and adds this directive:
#     `include /etc/nginx/conf.d/*.conf;`
#
# The `docker-openresty` file `nginx.vh.default.conf` is copied to
# `/etc/nginx/conf.d/default.conf`.  It contains the `server section
# of the upstream `nginx.conf`.
#
# See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
#

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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"';

    #access_log  logs/access.log  main;

    # See Move default writable paths to a dedicated directory (#119)
    # https://github.com/openresty/docker-openresty/issues/119
    client_body_temp_path /var/run/openresty/nginx-client-body;
    proxy_temp_path       /var/run/openresty/nginx-proxy;
    fastcgi_temp_path     /var/run/openresty/nginx-fastcgi;
    uwsgi_temp_path       /var/run/openresty/nginx-uwsgi;
    scgi_temp_path        /var/run/openresty/nginx-scgi;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    
    server {
        listen 80 default_server;
        location / {
            more_set_input_headers "X-Custom: hijack";
            return 200 "X-Custom: $http_x_custom\n";
        }
    }

    # include /etc/nginx/conf.d/*.conf;
}

run openresty in docker.

/tmp$ docker run --name openresty -d -v /tmp/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf --rm -p 8080:80 openresty/openresty:alpine

then send request to openresty.

$ curl -v http://localhost:8080/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: openresty/1.15.8.2
< Date: Mon, 21 Oct 2019 06:11:28 GMT
< Content-Type: application/octet-stream
< Content-Length: 11
< Connection: keep-alive
< 
X-Custom: 
* Connection #0 to host localhost left intact

expect return X-Custom: hijack, but got X-Custom:

PeerXu avatar Oct 21 '19 06:10 PeerXu

i try install apt-get install libnginx-mod-http-headers-more-filter everything is work

odysahe avatar Oct 14 '23 12:10 odysahe

expect return X-Custom: hijack, but got X-Custom:

please refer to README.markdown:279

more_set_input_headers runs after the standard rewrite_module, so there is no chance of running it before return 200 "X-Custom: $http_x_custom\n";

you can try: echo $http_x_custom;

lynch1981 avatar Oct 23 '23 17:10 lynch1981