【问题标题】:cors issue on server but not on localhost服务器上的cors问题,但不是本地主机上的问题
【发布时间】:2020-04-17 17:10:50
【问题描述】:

我正在使用 lighthouse-php 作为 graphQL 包的 laravel 7 项目。

在 localhost 上一切正常,但在 Ubuntu 18.04 ec2 nginx 服务器上,它给了我 CORS 问题。

请注意:- 1)客户端和服务器都在http上。

2) 我的 cors.php

return [

    /*
    |--------------------------------------------------------------------------
    | Cross-Origin Resource Sharing (CORS) Configuration
    |--------------------------------------------------------------------------
    |
    | Here you may configure your settings for cross-origin resource sharing
    | or "CORS". This determines what cross-origin operations may execute
    | in web browsers. You are free to adjust these settings as needed.
    |
    | To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
    |
    */

    'paths' => ['api/*', 'graphql'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => false,

    'max_age' => false,

    'supports_credentials' => false,

];

【问题讨论】:

  • 你在config/cores.php完成了配置吗?
  • 是的 .. 它是从 localhost 复制过来的 .. 我已经用这些信息更新了问题

标签: laravel ubuntu nginx laravel-lighthouse


【解决方案1】:

我认为您的 Nginx 会覆盖添加到您的 Location 块中的标题:

location {
  //...
  add_header 'Access-Control-Allow-Origin' '*';
  add_header 'X-Frame-Options' 'ALLOW-FROM *';
  //...
}

【讨论】:

  • 实际上我没有输入 server_name 并且它在网络上打开了 laravel 但是当 graphql 服务器试图点击它时它不起作用.. 感谢您抽出时间和回答.. 保持安全和快乐的编码
猜你喜欢
  • 2018-07-09
  • 2017-06-12
  • 2015-10-15
  • 2018-08-13
  • 1970-01-01
  • 1970-01-01
  • 2011-05-30
  • 1970-01-01
  • 2020-12-22
相关资源
最近更新 更多