openresty / headers-more-nginx-module

Set, add, and clear arbitrary output headers in NGINX http servers
1.65k stars 221 forks source link

more_set_input_headers not working #92

Open ZTzha opened 5 years ago

ZTzha commented 5 years ago

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?

agentzh commented 5 years ago

@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 commented 5 years ago

@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.

PeerXu commented 4 years ago

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:

odysahe commented 11 months ago

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

lynch1981 commented 11 months ago

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;

weiguorong commented 3 months ago

server { listen 80; listen [::]:80; server_name localhost;

#access_log  /var/log/nginx/host.access.log  main;
location / {
    more_set_input_headers 'Host: mybo';

    root   /usr/share/nginx/html;
    index  index.html index.htm;
}
#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

}

curl -v http://127.0.0.1:8088/