请问在openresty中创建网站(wordpress)后,如何在openresty中配置跨域访问?在配置项加了以下配置项后不生效
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
通过域名可以访问网站,但是报跨域错误:
Access to font at 'http://xxx:8080/wp-content/themes/timelines/fonts/fa-solid-900.woff2' from origin 'http://xxx.top:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
您好,按照该帖的内容修改后还是不行,还是相同的提示,openresty配置如下
server {
listen 80 ;
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods '*';
add_header Access-Control-Allow-Headers '*';
if ($request_method = 'OPTIONS') {
return 200;
}
server_name coolspace.top;
index index.php index.html index.htm default.php default.htm default.html;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
access_log /www/sites/coolspace/log/access.log;
error_log /www/sites/coolspace/log/error.log;
location ^~ /.well-known/acme-challenge {
allow all;
root /usr/share/nginx/html;
}
location / {
proxy_pass http://127.0.0.1:8080;
}
}