R
R
RoffDaniel2020-10-31 17:15:47
Nginx
RoffDaniel, 2020-10-31 17:15:47

How to correctly pass HTTP authorization through Nginx to Apache?

Hello! I ran into a problem that I can't figure out... How can I correctly pass HTTP authorization through Nginx to Apache? I have Nginx acting as a proxy_pass, passing all data to Apache. But, $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] return empty. How to be?
Here are the Nginx and Apache configs:

location / {
    proxy_pass http://10.0.20.20:8080;
    proxy_redirect        off;
    set_real_ip_from 10.0.20.20;
    real_ip_recursive on;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass_header Set-Cookie;
    }

<VirtualHost 10.0.20.20:8080>
  ServerName domain.com

  ServerAdmin [email protected]
  DocumentRoot /var/www/domain.com/test-site/public

  ErrorLog ${APACHE_LOG_DIR}/svm-test-site_error.log
  CustomLog ${APACHE_LOG_DIR}/svm-test-site_access.log vhost_combined
  
  ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/var/www/domain.com/test-site/public"
  AccessFileName .htaccess
</VirtualHost>
<Directory /var/www/domain.com/test-site/public>
  Options +Includes +ExecCGI
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>


Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2020-10-31
@RoffDaniel

Nginx passes all received headers internally by default, nothing needs to be specially configured. Deal with Apache and PHP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question