为什么浏览器将 info.html 的服务器 API 显示为 Apache 2.0 处理程序,而将 info.php 显示为 FPM/FastCGI?
Why browser show Server API for info.html as Apache 2.0 Handler but info.php as FPM/FastCGI?
环境:centos7+php7.2.
我按照教程所说构建 FPM/FastCGI。
build FPM/FastCGI
在/etc/httpd/conf.d/php.conf
中显示我的重要配置。
<IfModule mod_php7.c>
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"
</IfModule>
在我的 vps 目录 /var/www/html
.
中用两个名称 info.php
和 info.html
分配相同的内容
<?php
phpinfo();
?>
在浏览器中键入 vps_ip/info.php
,显示以下输出:
Code:
System Linux localhost.localdomain 2.6.32-042stab132.1 #1 SMP Wed Jul 11 13:51:30 MSK 2018 x86_64
Build Date Oct 10 2018 10:01:57
Server API FPM/FastCGI
Virtual Directory Support disabled
在浏览器中输入 vps_ip/info.html
,显示以下输出:
System Linux localhost.localdomain 2.6.32-042stab132.1 #1 SMP Wed Jul 11 13:51:30 MSK 2018 x86_64
Build Date Oct 10 2018 10:01:57
Server API Apache 2.0 Handler
Virtual Directory Support disabled
为什么我的浏览器将 info.html
的 Server API
显示为 Apache 2.0 Handler
,
但将 info.php
的 Server API
显示为 FPM/FastCGI
?
尝试为 html 设置 FilesMatch
,如下所示。
<FilesMatch ".+\.html$">
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
键入 vps_ip/info.html
,我得到错误:
Access denied.
cat /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/html">
Options +Indexes +FollowSymLinks +ExecCGI
AddHandler php-fastcgi .php
Action php-fastcgi /cgi-bin/php.fastcgi
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-httpd-php .php .html
AddType application/x-httpd-php-source .phps
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
apachectl -S
VirtualHost configuration:
*:80 localhost.localdomain (/etc/httpd/conf/httpd.conf:130)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex fcgid-pipe: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex fcgid-proctbl: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: _RH_HAS_HTTPPROTOCOLOPTIONS
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
我想用 apache 的 FPM/FastCGI
方式打开 vps_ip/info.html
,而不是 Apache 2.0 Handler
方式。
1.Set配置在php.ini
cgi.fix_pathinfo=0
2.Set配置在www.conf
改变
security.limit_extensions = .php .php3 .php4 .php5
进入
security.limit_extensions =
现在允许所有扩展。
sudo setenforce Permissive
sudo systemctl restart httpd
sudo systemctl restart php72-php-fpm
检查在浏览器中键入 your_vps_ip/info.html
时会发生什么。
它在您的配置中:
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
改成这样:
<FilesMatch \.(php|phar|html)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
配置您的 php.conf 就像下面的代码或根据您的 OS 类型
<IfModule mod_php7.c>
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"
</IfModule>
配置可以根据 MAC、Windows 和 Linux 变化。
环境:centos7+php7.2.
我按照教程所说构建 FPM/FastCGI。
build FPM/FastCGI
在/etc/httpd/conf.d/php.conf
中显示我的重要配置。
<IfModule mod_php7.c>
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"
</IfModule>
在我的 vps 目录 /var/www/html
.
info.php
和 info.html
分配相同的内容
<?php
phpinfo();
?>
在浏览器中键入 vps_ip/info.php
,显示以下输出:
Code:
System Linux localhost.localdomain 2.6.32-042stab132.1 #1 SMP Wed Jul 11 13:51:30 MSK 2018 x86_64
Build Date Oct 10 2018 10:01:57
Server API FPM/FastCGI
Virtual Directory Support disabled
在浏览器中输入 vps_ip/info.html
,显示以下输出:
System Linux localhost.localdomain 2.6.32-042stab132.1 #1 SMP Wed Jul 11 13:51:30 MSK 2018 x86_64
Build Date Oct 10 2018 10:01:57
Server API Apache 2.0 Handler
Virtual Directory Support disabled
为什么我的浏览器将 info.html
的 Server API
显示为 Apache 2.0 Handler
,
但将 info.php
的 Server API
显示为 FPM/FastCGI
?
尝试为 html 设置 FilesMatch
,如下所示。
<FilesMatch ".+\.html$">
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
键入 vps_ip/info.html
,我得到错误:
Access denied.
cat /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/html">
Options +Indexes +FollowSymLinks +ExecCGI
AddHandler php-fastcgi .php
Action php-fastcgi /cgi-bin/php.fastcgi
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-httpd-php .php .html
AddType application/x-httpd-php-source .phps
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
apachectl -S
VirtualHost configuration:
*:80 localhost.localdomain (/etc/httpd/conf/httpd.conf:130)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex fcgid-pipe: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex fcgid-proctbl: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: _RH_HAS_HTTPPROTOCOLOPTIONS
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
我想用 apache 的 FPM/FastCGI
方式打开 vps_ip/info.html
,而不是 Apache 2.0 Handler
方式。
1.Set配置在php.ini
cgi.fix_pathinfo=0
2.Set配置在www.conf
改变
security.limit_extensions = .php .php3 .php4 .php5
进入
security.limit_extensions =
现在允许所有扩展。
sudo setenforce Permissive
sudo systemctl restart httpd
sudo systemctl restart php72-php-fpm
检查在浏览器中键入 your_vps_ip/info.html
时会发生什么。
它在您的配置中:
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
改成这样:
<FilesMatch \.(php|phar|html)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
配置您的 php.conf 就像下面的代码或根据您的 OS 类型
<IfModule mod_php7.c>
<FilesMatch \.(php|phar)$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"
</IfModule>
配置可以根据 MAC、Windows 和 Linux 变化。