Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable HTTP Authorization Header on the Nginx server? #61

Open
Demoxing opened this issue Mar 17, 2022 · 4 comments
Open

How to enable HTTP Authorization Header on the Nginx server? #61

Demoxing opened this issue Mar 17, 2022 · 4 comments

Comments

@Demoxing
Copy link

I am trying to configure JWT Authentication for WordPress REST API. But the problem is there is no direct config available for enabling the HTTP Authorization Header. Nginx doesn't have a .htaccess file, so I can't add the rewrite rules.

Here are the rules for apache based server:

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

I believe it's not going to work with Nginx. What is the solution available for the Nginx side?

@pesseba
Copy link
Collaborator

pesseba commented Mar 17, 2022

I don't know Ngix too, but my host applied this configuration for me:


if ($http_authorization ~ "^(.*)"){
	set $rule_0 1;
}
if ($rule_0 = "1"){
	set $http_authorization %1;
}

@Demoxing
Copy link
Author

if ($http_authorization ~ "^(.*)"){
set $rule_0 1;
}
if ($rule_0 = "1"){
set $http_authorization %1;
}

Where do I have to add this code? In which file?

@shayr1
Copy link

shayr1 commented Apr 25, 2022

For future reference, this goes in nginx's server block inside

server {
  server_name yourdomain.com;
  ...rest of server block

  if ($http_authorization ~ "^(.*)"){
    set $rule_0 1;
  }
  if ($rule_0 = "1"){
    set $http_authorization %1;
  }

}

On Ubuntu default installations configuration files can be found under /etc/nginx/sites-available/. On hosting companies if there's a panel there should be a place that let the user edit "Server Blocks"

@dominic-ks
Copy link
Collaborator

Hey @shayr1 @Demoxing is this now working on nginx for you with this config? If so we could add it to the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants