• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion
  • Please beaware of a breaking change in the REST API on the next Plesk release (18.0.62).
    Starting from Plesk Obsidian 18.0.62, requests to REST API containing the Content-Type header with a media-type directive other than “application/json” will result in the HTTP “415 Unsupported Media Type” client error response code. Read more here

Question Empty Authorization header on PHP with nginx

nicojmb

New Pleskian
Hi,

I'm developing a PHP RestAPI server with JWT and Bearer Auth.

In my client side (postman) send the header authorization but in PHP the variable $_SERVER['HTTP_AUTHORIZATION'] is empty.

Here is my plesk configuration is (details in attaached images):

  • Hosting Settings: PHP 7.4.11 - FPM served by nginx


¿How get this headers with nginx in my php code?
 

Attachments

  • hosting_settings.png
    hosting_settings.png
    60 KB · Views: 14
  • php_settings.png
    php_settings.png
    49.1 KB · Views: 11
  • postman_cacll.png
    postman_cacll.png
    14.3 KB · Views: 11
I think that in this case you need to add two directives to Nginx like

Code:
proxy_set_header Authorization $http_authorization;
proxy_pass_header Authorization;
I have not tested this, but think this should work in the "Directivas adicionales de nginx" field.
 
I think that in this case you need to add two directives to Nginx like

Code:
proxy_set_header Authorization $http_authorization;
proxy_pass_header Authorization;
I have not tested this, but think this should work in the "Directivas adicionales de nginx" field.

Hi, added this directives but do not work, the $_SERVER['HTTP_AUTHORIZATION'] still empty.

1603889747125.png
 
Hi, i don´t know whay, but if i add this apache directive works:

Apache config:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

i thought apache parameters are not used when nginx proxy is enabled
 
Nginx "proxy" means that Nginx serves static files while it forwards all other requests to Apache. .htaccess and other Apache settings are used by Apache as always, just not on static files that are served by Nginx.
 
Hi, i don´t know whay, but if i add this apache directive works:

Apache config:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

i thought apache parameters are not used when nginx proxy is enabled
Hi nicojmb,
Could you explain more details about the steps about how you did it?
Did you follow this?
 
Hi nicojmb,
Could you explain more details about the steps about how you did it?
Did you follow this?

Hi,

Add at top of .htaccess this line:

Apache config:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
 
Back
Top