Solution to the problem of information loss with "_" in header when using Nginx proxy

Solution to the problem of information loss with "_" in header when using Nginx proxy

Preface

When developing a gateway project, the signature sign_key information is put into the request header when making a request, and then taken out of the header when receiving the request. This works when debugging locally, but after going online, it is found that it cannot be obtained through the Nginx proxy.

location / {
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header Host $http_host;
 proxy_set_header X-Nginx-Proxy true;

 add_header Proxy-Node $upstream_addr;
 add_header Proxy-Status $upstream_status; 
 
 proxy_http_version 1.1;
 proxy_pass http://tianusa;
 }

Later I found out that the reason was that Nginx had some restrictions on headers, and underscores (_) were not supported.

Solution:

1. No underscores

Change the underscore _ to something else, such as sign_key to sign-key

2. Remove the limitations of Nginx from the root

By default, Nginx will automatically ignore any '_' in the request header.

The solution is to add the following configuration to the http section of the nginx.conf configuration file in nginx:

underscores_in_headers on; (default underscores_in_headers is off)

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • How to configure nginx+php+mysql in docker
  • Solution to invalid Nginx cross-domain setting Access-Control-Allow-Origin
  • Example method of deploying react project on nginx
  • Use nginx.vim tool for syntax highlighting and formatting configuration nginx.conf file
  • Detailed explanation of the pitfalls of add_header in nginx configuration tutorial
  • How to configure two-way certificate verification on nginx proxy server
  • Shell script nginx automation script
  • How to create an Nginx server with Docker
  • A brief discussion on why daemon off is used when running nginx in docker
  • nginx proxy_cache batch cache clearing script introduction

<<:  Explaining immutable values ​​in React

>>:  How to find websites with SQL injection (must read)

Recommend

Native Js implementation of calendar widget

This article example shares the specific code of ...

A brief analysis of the four import methods and priorities in CSS

First: 4 ways to introduce CSS There are four way...

Solution to MySQL server login error ERROR 1820 (HY000)

Fault site: Log in to the MySQL server and get th...

MySQL triggers: creating multiple triggers operation example analysis

This article uses an example to describe the crea...

A brief introduction to bionic design in Internet web design

When it comes to bionic design, many people will t...

Vue implements the magnifying glass function of the product details page

This article shares the specific code of Vue to i...

How to remotely connect to MySQL database with Navicat Premium

The party that creates a new connection is equiva...

MySQL series multi-table join query 92 and 99 syntax examples detailed tutorial

Table of contents 1. Cartesian product phenomenon...

SQL implementation of LeetCode (196. Delete duplicate mailboxes)

[LeetCode] 196.Delete Duplicate Emails Write a SQ...

js to realize the mouse following game

This article shares the specific code of js to im...

UDP connection object principle analysis and usage examples

I wrote a simple UDP server and client example be...