'Can anyone help to change this .htaccess rule to nginx?

I am using a wordpress plugin name JWT Authentication for WP REST API, it has some rules written in .htaccess but i am using nginx server and want to add these rule in nginx configurations

rewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]


Solution 1:[1]

You can easily convert your .htaccess rule to nginx Please follow the blog here you can find your solution:

https://www.nginx.com/blog/converting-apache-to-nginx-rewrite-rules/

Solution 2:[2]

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

You shouldn't need to convert this Apache rule to work in Nginx.

This rule is a workaround for a specific Apache security feature (hobble) that is imposed by Apache when PHP is installed as CGI, as opposed to an Apache module. AFAIK, the same issue does not apply to Nginx.

(Basically, Apache prevents the Authorization HTTP request header being sent to all backend CGI scripts to prevent usernames/passwords being inadvertently sent to untrusted scripts. Unfortunately, this also includes PHP when installed as (Fast)CGI.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhammd Noman Rauf
Solution 2