• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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