Nginx Redirect POST Request Data Loss Issue

This article introduces the Nginx redirect POST request data loss issue, including its causes, implementation details, and relevant resources. These steps can help improve efficiency when dealing with Nginx redirect POST data loss problems.

Jul 19, 2017 · 1 min read · 131 Words · -Views -Comments · Programming
Deployment Operations 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

Created two websites, Website A and Website B. Website A receives POST submissions and then redirects to Website B. The redirection is configured in Nginx. For specific configuration syntax, please refer to the official Nginx documentation. Here I’ll only show the key statements.

Original Configuration

#  rewrite ^.+ http://b.com$uri;

However, after testing, we discovered an issue: when redirecting to B, the form submission data would be lost.

Solution

After researching, we found that rewrite indeed causes POST data loss. Therefore, we should use 307 redirection. The specific configuration is as follows:

return 307 $scheme://b.com$request_uri;

Explanation

HTTP Status Code 307 Meaning

HTTP-307 is a temporary redirect, indicating that the request has been temporarily moved to the given target address. Both the method and request body will be reused for the redirected request.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover