在 apache 中只为一个虚拟主机关闭 cookie_secure?

turn off cookie_secure in apache for only one virtual host?

我在 php.ini 中打开了 session.cookie_secure。这会影响我服务器上的每个虚拟主机。 (这实际上是我的开发服务器,但我更喜欢让设置尽可能靠近我的生产站点。)

但是我在同一个 Apache 服务器上的虚拟主机上有一个开发站点。我不想在该站点上显示 session.cookie_secure。有没有办法使用虚拟主机文件为该站点关闭它?

我找到了这个网站: https://geekflare.com/httponly-secure-cookie-apache/

他们表明要打开它,您需要:

Header edit Set-Cookie ^(.*)$ ;HttpOnly;Secure

我可以通过虚拟主机取消设置吗?我试过这个,但它不起作用:

Header edit Set-Cookie ^(.*)$ ;HttpOnly;Secure=Off

如果 PHP 作为 Apache 模块运行,您可以在 .htaccess 文件或虚拟主机配置中进行设置:

php_flag session.cookie_secure Off

如果它像CGI/FCGI一样运行,那就更复杂了。我建议切换到 PHP-FPM 并为该虚拟主机设置一个特定的池。有关详细信息,请参阅 https://serversforhackers.com/video/php-fpm-multiple-resource-pools or https://www.linode.com/docs/web-servers/apache/running-fastcgi-php-fpm-on-debian-7-with-apache(您可能需要根据您使用的 Linux 发行版进行调整)。