php - Apache+mod_php 太慢了
问题描述
我在使用 mod_php 设置 Apache 服务器时遇到问题。我有一个网站,其 index.php 页面在 ~200 毫秒内生成。但是 Apache 在大约 1.5 秒内提供它。为什么会出现这种放缓?
如果需要,我的/etc/apache2/ports.conf
文件是:
Listen 80
<VirtualHost *:80>
ServerName mysite.local
ServerAlias www.mysite.local
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:9999/
ProxyPassReverse / http://localhost:9999/
</VirtualHost>
我的文件/etc/apache2/sites-available/mysite.local.conf
是:
Listen 9999
User max
Group max
<VirtualHost *:9999>
ServerName 127.0.0.1:9999
DocumentRoot /home/max/www/mysite.local/www/html/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/max/www/mysite.local/www>
Options FollowSymLinks
AllowOverride All
#Order allow,deny
#Allow from all
Require all granted
</Directory>
ErrorLog /home/max/www/mysite.local/logs/error.log
LogLevel warn
CustomLog /home/max/www/mysite.local/logs/access.log combined
</VirtualHost>
我的主要问题是为什么这么慢,如何让它更快?我已经测试过将 index.php 内容放入一个普通的 html 文件中,并且在大约 10 毫秒内提供服务。所以问题可能出在 mod_php 上?提前致谢。
解决方案
一个原因可能是 apache 在每个请求的根目录的每个目录中递归地检查 .htaccess 文件。apache 使用非常广泛,但速度不是很快,甚至没有优化。
我肯定会建议结合 php-fpm 的 nginx 服务器。配置非常简单,如果您熟悉 apache,使用 nginx 应该不会有问题。如何:https ://tecadmin.net/setup-nginx-php-fpm-on-ubuntu-20-04/
推荐阅读
- sap-cloud-sdk - 如何在 SAP Cloud SDK 3.0 及更高版本中获取用户信息和权限
- ios - CBCentralManager,didConnect 外围设备:永远不会被调用
- uitextfield - Swiftui TextField onkeypress
- excel - VBA中的函数给我素数不起作用
- apache-kafka - 动物园管理员卡夫卡
- javascript - 想在按回车但重新加载时发送消息
- javascript - 为什么控制台显示typeError?
- wordpress - 如何从 Wordpress API 获取数据?
- go - 如何在数学/大浮点数中进行舍入?
- npm - 如何在 jalali 日历中找到公共日