gpt4 book ai didi

apache - 如何在apache2中允许跨域请求

转载 作者:行者123 更新时间:2023-12-03 15:09:13 33 4
gpt4 key购买 nike

这是我的配置文件。

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost:80
DocumentRoot /var/www/XXX
<Directory />
Options None
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory /var/www/qvbn-app-web-ctrl>
Options FollowSymLinks
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
Header set Access-Control-Allow-Origin "*"
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

当我尝试重新加载 apache2 iT 时出现错误:
   Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.

我不知道如何启用 CORS。我跟着这个:
http://enable-cors.org/server_apache.html

最佳答案

在 httpd.conf

  • 确保已加载这些:

  • LoadModule headers_module modules/mod_headers.so

    LoadModule rewrite_module modules/mod_rewrite.so
  • 在目标目录中:

  • <Directory "**/usr/local/PATH**">
    AllowOverride None
    Require all granted

    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"
    Header always set Access-Control-Max-Age "600"

    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]

    </Directory>

    If running outside container, you may need to restart apache service.

    关于apache - 如何在apache2中允许跨域请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29150384/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com