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

How to install vim editor in Linux (Ubuntu 18.04)

You can go to the Ubuntu official website to down...

VMware15/16 Detailed steps to unlock VMware and install MacOS

VMware version: VMware-workstation-full-16 VMware...

Why the disk space is not released after deleting data in MySQL

Table of contents Problem Description Solution Pr...

How to remove the blue box that appears when the image is used as a hyperlink

I recently used Dreamweaver to make a product pres...

Our thoughts on the UI engineer career

I have been depressed for a long time, why? Some t...

Vite2.0 Pitfalls

Table of contents Vite project build optimization...

Complete Tutorial on Deploying Java Web Project on Linux Server

Most of this article refers to other tutorials on...

Implementation of fastdfs+nginx cluster construction

1. Introduction to fastdfs 1. What is fastdfs Fas...

How to add a certificate to docker

1. Upgrade process: sudo apt-get update Problems ...

...

Vue.js application performance optimization analysis + solution

Table of contents 1. Introduction 2. Why do we ne...

Before making a web page, let’s take a look at these so-called specifications

This article has compiled some so-called specific...

Control the vertical center of the text in the HTML text box through CSS

When the height attribute of Text is defined, the ...