记录phpstudy 通过apache部署php,无法获取请求头中的Authorization字段

记录phpstudy 通过apache部署php,无法获取请求头中的Authorization字段

问题出现的背景

背景:
因为不同项目使用了多个版本的php,重装系统后,因为phpstudy切换php版本更便捷,
所以php集成环境从xampp改到了phpstudy。

系统信息:
操作系统:Windows 10,
安装的php版本:php 7.1,php 7.3,php 8.0,php 8.2


项目信息:
php版本:php 8.0
web端:vue3 + vite5
MySQL :msyql 5.7.44

问题描述

在一个web项目中,可能是apache配置中开启了cgi之类的功能,php无法获取到web发送的http请求头中的“Authorization”字段,
导致web请求业务无法通过检验。

解决方式

找到apache的httpd.conf配置目录,如D:\phpstudy_pro\Extensions\Apache2.4.39\conf\httpd.conf,
添加“SetEnvIf Authorization “(.*)” HTTP_AUTHORIZATION=$1”,如下图所示,然后重启apache即可。

<IfModule dir_module>
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    DirectoryIndex index.php index.html
</IfModule>

其他

phpstudy工具配置多个网站以及同端口配置多个alias。
网站配置文件路径,并不是在apache默认的httpd.conf里面,而是在vhost文件夹内,
如:D:\phpstudy_pro\Extensions\Apache2.4.39\conf\vhosts
通过phpstudy工具配置的站点目录
别名配置

<VirtualHost _default_:8230>
    DocumentRoot "D:/phpstudy_pro/WWW/erp/public/"
    FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php8.0.2nts"
    AddHandler fcgid-script .php
    FcgidWrapper "D:/phpstudy_pro/Extensions/php/php8.0.2nts/php-cgi.exe" .php
    ErrorLog "D:/phpstudy_pro/Extensions/Apache2.4.39/logs/localhost_error.log"
    CustomLog "D:/phpstudy_pro/Extensions/Apache2.4.39/logs/localhost_acess.log" common

 # 禁止直接访问根路径 /
    <LocationMatch "^/$">
        Require all denied
    </LocationMatch>
    
  #别名
  alias /erp "D:/phpstudy_pro/WWW/erp/public/"
  <Directory "D:/phpstudy_pro/WWW/erp/public/">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
	  DirectoryIndex index.php index.html error/index.html
  </Directory>
# 按上述样式添加多个别名

  ErrorDocument 400 /error/400.html
  ErrorDocument 403 /error/403.html
  ErrorDocument 404 /error/404.html
  ErrorDocument 500 /error/500.html
  ErrorDocument 501 /error/501.html
  ErrorDocument 502 /error/502.html
  ErrorDocument 503 /error/503.html
  ErrorDocument 504 /error/504.html
  ErrorDocument 505 /error/505.html
  ErrorDocument 506 /error/506.html
  ErrorDocument 507 /error/507.html
  ErrorDocument 510 /error/510.html
</VirtualHost>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值