xyz*_*xyz 12 php apache google-chrome cors angular
语言/工具版本:
问题:
我有一个Angular2应用程序,它使用PHP应用程序作为所有XHR请求的API.该应用程序工作正常,但是当Use a prediction service to load pages more quickly在Chrome中启用该选项时,并且当重新加载应用程序时ngOnInit(),在组件内部发送的HTTP请求会被卡住很长时间.请求将在10s-2-3mins之后自行解决,或者如果我发送另一个请求(例如,DOM上的click事件请求),请求也将解析
我试过的事情:
GET请求,然后等待,一旦解决,将有一个成功的OPTIONS请求,然后成功GET.http://api.randomuser.me/而不是请求我的API端点.在这种情况下,请求成功没有任何延迟(尽管它显示CORS错误).所以我认为问题在于我的后端API或Apache Web服务器.我还想分享我的虚拟主机配置.如果您发现任何问题:
<VirtualHost *:80>
ServerName someName.api
DocumentRoot path_to_public_dir
SetEnv APPLICATION_ENV development
<Directory path_to_public_dir>
SetEnvIf Origin "http(s)?://(www\.)?(local\.)?(localhost:4200|someDomain.com)$" AccessControlAllowOrigin=$0
Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} –d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Options -Indexes +MultiViews +FollowSymLinks
AllowOverride none
Order Allow,Deny
Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
请注意:
Access-Control-Allow-Origin
在应用程序本身内设置标题,但仍然没有运气.您对这种行为的可能原因的建议/答案将非常有帮助.
嗯,我认为,做以下操作已经消除了我机器的滞后.
在解决之前,这是我的假设:
解:
我mpm为apache 包含了模块文件.您可以在httpd.conf文件中找到以下行:
#Include conf/extra/httpd-mpm.conf 并取消注释.
Windows使用mpm_winnt_module作为mpm.
此多处理模块(MPM)是Windows NT操作系统的默认设置.它使用单个控制进程启动单个子进程,该进程又创建线程来处理请求
找到下面的行并取消注释:
EnableMMAP off
EnableSendfile on
AcceptFilter http none
AcceptFilter https none
#Extra Notes
#mmap is memory map by apache, don't know I have uncommented this, had read about
this somewhere, but anyway its Off so should not be a Burden on OS
#EnableSendFile:Delivering static files? This link may help:
https://groups.drupal.org/node/68333
#AcceptFilter: windows mpm module, suggests to keep it as none.
I went through this : https://httpd.apache.org/docs/2.4/mod/core.html
and have set AcceptFilter http/https as "connect", it works fine for me.
Please note: I am using Apache 2.4.23
Run Code Online (Sandbox Code Playgroud)而已!
我离开这个问题是不可接受的,因为:
winnt模块,但是在我的apache目录中的任何地方都找不到模块文件,虽然反映了ThreadsPerChild的变化,我猜apache不需要外部winnt模块.failed and finshed在Chrome控制台中看到每个请求的交叉
请求.您的答案将非常有价值并使事情变得更加清晰.