Rails Passenger Glyphicon CORS Cloudfront NGINX 问题

2023-11-25

所以我知道 stackoverflow 上有关于 CORS Nginx、Cloudfront 和 Heroku 的这些问题,但由于某种原因我无法让它工作。我一直在关注这个问题的答案:

如何使用 Rails、nginx 和乘客配置“Access-Control-Allow-Origin”?

但是我似乎无法弄清楚将自定义代码块放在哪里:

config/nginx.conf.erb

接下来,编辑配置文件 config/nginx.conf.erb,找到 块如下所示:

location @static_asset {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    add_header ETag "";
} ...and add the two Access-Control lines:

to

>     location @static_asset {
>         gzip_static on;
>         expires max;
>         add_header Cache-Control public;
>         add_header ETag "";
>         add_header Access-Control-Allow-Origin *;
>         add_header Access-Control-Request-Method *;
>     } That's it. This will work in production, but not in development, due to config.assets differences between the two.

在我的 Nginx 配置中。我正在使用 Phusion Passenger 5.0.23。 Nginx 配置在我从乘客那里提取的配置中没有 location @static_asset 块。它确实有一个用于自定义配置的部分,但这对我来说不起作用。我的字形继续显示为方框 我该如何让它工作? 我也尝试过这个Phusion Passenger + Heroku + Cloudfront:CORS 配置

当前配置文件

    ##########################################################################
#  Passenger Standalone is built on the same technology that powers
#  Passenger for Nginx, so any configuration option supported by Passenger
#  for Nginx can be applied to Passenger Standalone as well. You can do
#  this by direct editing the Nginx configuration template that is used by
#  Passenger Standalone.
#
#  This file is the original template. DO NOT EDIT THIS FILE DIRECTLY.
#  Instead, make a copy of this file and pass the `--nginx-config-template`
#  parameter to Passenger Standalone.
#
#  Learn more about using the Nginx configuration template at:
#  https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template
#
#  *** NOTE ***
#  If you customize the template file, make sure you keep an eye on the
#  original template file and merge any changes. New Phusion Passenger
#  features may require changes to the template file.
##############################################################

<%= include_passenger_internal_template('global.erb') %>

worker_processes 1;
events {
    worker_connections 1024;
}

http {
    <%= include_passenger_internal_template('http.erb', 4) %>



    ### BEGIN your own configuration options ###
    # This is a good place to put your own config
    # options. Note that your options must not
    # conflict with the ones Passenger already sets.
    # Learn more at:
    # https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template

    ### END your own configuration options ###

    default_type application/octet-stream;
    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;
    client_max_body_size 1024m;
    access_log off;
    keepalive_timeout 60;
    underscores_in_headers on;
    gzip on;
    gzip_comp_level 3;
    gzip_min_length 150;
    gzip_proxied any;
    gzip_types text/plain text/css text/json text/javascript
        application/javascript application/x-javascript application/json
        application/rss+xml application/vnd.ms-fontobject application/x-font-ttf
        application/xml font/opentype image/svg+xml text/xml;

    <% if @app_finder.multi_mode? %>
        # Default server entry for mass deployment mode.
        server {
            <%= include_passenger_internal_template('mass_deployment_default_server.erb', 12) %>
        }
    <% end %>

    <% for app in @apps %>
    server {
        <%= include_passenger_internal_template('server.erb', 8, true, binding) %>
        <%= include_passenger_internal_template('rails_asset_pipeline.erb', 8, false) %>

        ### BEGIN your own configuration options ###
        # This is a good place to put your own config
        # options. Note that your options must not
        # conflict with the ones Passenger already sets.
        # Learn more at:
        # https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template

        # CloudFront fix 
        location /public/* {
            gzip_static on;
            expires max;
            add_header Cache-Control public;
            add_header ETag "";
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Request-Method *;
        }


        ### END your own configuration options ###
    }
    passenger_pre_start <%= listen_url(app) %>;
    <% end %>
}

我遇到了同样的问题,这个配置对我有用:

    ##########################################################################
#  Passenger Standalone is built on the same technology that powers
#  Passenger for Nginx, so any configuration option supported by Passenger
#  for Nginx can be applied to Passenger Standalone as well. You can do
#  this by direct editing the Nginx configuration template that is used by
#  Passenger Standalone.
#
#  This file is the original template. DO NOT EDIT THIS FILE DIRECTLY.
#  Instead, make a copy of this file and pass the `--nginx-config-template`
#  parameter to Passenger Standalone.
#
#  Learn more about using the Nginx configuration template at:
#  https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template
#
#  *** NOTE ***
#  If you customize the template file, make sure you keep an eye on the
#  original template file and merge any changes. New Phusion Passenger
#  features may require changes to the template file.
##############################################################

<%= include_passenger_internal_template('global.erb') %>

worker_processes 1;
events {
    worker_connections 4096;
}

http {
    <%= include_passenger_internal_template('http.erb', 4) %>

    ### BEGIN your own configuration options ###
    # This is a good place to put your own config
    # options. Note that your options must not
    # conflict with the ones Passenger already sets.
    # Learn more at:
    # https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template

    ### END your own configuration options ###

    default_type application/octet-stream;
    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;
    client_max_body_size 1024m;
    access_log off;
    keepalive_timeout 60;
    underscores_in_headers on;
    gzip on;
    gzip_comp_level 3;
    gzip_min_length 150;
    gzip_proxied any;
    gzip_types text/plain text/css text/json text/javascript
        application/javascript application/x-javascript application/json
        application/rss+xml application/vnd.ms-fontobject application/x-font-ttf
        application/xml font/opentype image/svg+xml text/xml;

    <% if @app_finder.multi_mode? %>
        # Default server entry for mass deployment mode.
        server {
            <%= include_passenger_internal_template('mass_deployment_default_server.erb', 12) %>
        }
    <% end %>

    <% for app in @apps %>
    server {
        <%= include_passenger_internal_template('server.erb', 8, true, binding) %>
        <%# <%= include_passenger_internal_template('rails_asset_pipeline.erb', 8, false) %1> %>

        ### BEGIN your own configuration options ###
        # This is a good place to put your own config
        # options. Note that your options must not
        # conflict with the ones Passenger already sets.
        # Learn more at:
        # https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template
        # Rails asset pipeline support.
        location ~ "^/assets/.+-([0-9a-f]{32}|[0-9a-f]{64})\..+" {
            error_page 490 = @static_asset;
            error_page 491 = @dynamic_request;
            recursive_error_pages on;

            if (-f $request_filename) {
                return 490;
            }
            if (!-f $request_filename) {
                return 491;
            }
        }
        location @static_asset {
            gzip_static on;
            expires max;
            add_header Cache-Control public;
            add_header ETag "";
            if ($http_origin ~* ((https?:\/\/[^\/]*\.herokuapp\.com(:[0-9]+)?))) {
                add_header 'Access-Control-Allow-Origin' "$http_origin";
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET, HEAD';
                add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
            }
        }
        location @dynamic_request {
            passenger_enabled on;
        }

        ### END your own configuration options ###
    }
    passenger_pre_start <%= listen_url(app) %>;
    <% end %>

    <%= include_passenger_internal_template('footer.erb', 4) %>
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails Passenger Glyphicon CORS Cloudfront NGINX 问题 的相关文章

随机推荐

  • 如何在 Windows 上安装 RedCloth?

    跑步时gem install RedCloth 在 Windows XP 上 我得到 Fetching RedCloth 4 2 8 gem 100 Temporarily enhancing PATH to include DevKit
  • 即时创建 zip,其中包含 csv 文件

    我正在尝试动态创建一个 zip 文件 其中包含一堆要从 servlet 返回的 csv 文件 这非常令人困惑 一点指导会很棒 以下是我需要以某种方式协同工作的代码块 output stream coming from httpRespons
  • Django - 避免在视图中重复代码的提示

    我正在从 PHP 背景转向通过 python 进行 Django 开发 主要是为了解决我认为最有意义的 MVC 或 MVT 尽管在这种模式中我开始注意到有很多重复的代码我的观点 例如 登录时我有关于我希望出现在每个页面上的用户的信息 尽管在
  • 在发布模式 Xamarin Android 中构建应用程序时,“链接程序集”任务意外失败问题

    尝试在 Xamarin Android 中构建应用程序发布模式时遇到以下问题 为什么会出现以及如何解决 严重性代码 说明 项目文件行源抑制状态错误 链接程序集 任务意外失败 Xamarin Android XamarinAndroidExc
  • 将多个 CSV 文件读入 Python Pandas Dataframe

    问题背后的一般用例是将多个 CSV 日志文件从目标目录读取到单个 Python Pandas DataFrame 中 以进行快速周转统计分析和图表 利用 Pandas 与 MySQL 的想法是全天定期进行数据导入或追加 统计分析 下面的脚本
  • 如何使用正则表达式验证中文输入?

    问题是我需要在客户端验证中将这种中文输入视为无效 当英文字符与汉字及空格混合的总长度 gt 10时 输入无效 假设 你的a你的a你的a你 或 你的你的你的你 长度为10 无效 但是 你的a你的a你的a 长度为9 就可以了 我使用 Javas
  • app.xaml.cs 中的依赖属性

    我是 WPF 新手 下面的问题对很多人来说可能看起来很愚蠢 请原谅我 如何在 app xaml cs 中创建依赖属性 事实上 我尝试创建它 下面的代码 public static DependencyProperty TempPropert
  • 烧瓶创建应用程序和设置单元测试

    所以我用这种方式设置了我的烧瓶 def create app config name app Flask name static folder designs UI template folder designs UI instance r
  • jQuery:查找部分类名[重复]

    这个问题在这里已经有答案了 我想看看是否 li 有一个特定的类 但问题是它们都是唯一的 但都包含一个常量字符串 unqID 我想检查一下是否 li li 有一个包含该字符串的类 如果不存在 则将新类添加到 li li 我知道如何查找元素是否
  • 如何调整 的宽度?

    我使用宽度属性作为 对于所有列 但在显示中 列没有调整 我可以通过这种方式进入吗 如果 请指导我实现我想要的列宽 您必须使用columnClasses属性并用逗号 分隔每个列样式 下面的代码示例展示了如何使用columnClassess属性
  • R--在字符串中添加前导零,没有固定的字符串格式

    我有一个专栏如下 9453 55489 4588 18893 4457 2339 45489HQ 7833HQ 如果数字少于 5 位 我想添加前导零 然而 有些号码最后有 HQ 有些没有 我确实检查了其他帖子 他们在 HQ 部分没有类似的问
  • 实体框架连接字符串问题

    我正在制作一个小库 DLL 来管理用户及其角色 权限 计划是能够将此 dll 添加到 MVC 项目中并能够操作用户 角色等 所有数据都驻留在 SQL 数据库中 我正在使用实体框架进行数据访问 因此 当我初始化一个新的 RoleManager
  • Convert.ToInt32 和 (int) 有什么区别?

    以下代码会引发编译时错误 例如 无法将类型 string 转换为 int string name Session name1 ToString int i int name 而下面的代码可以成功编译并执行 string name Sessi
  • C - 并行执行 fork() 时 wait(NULL) 的含义

    在下面的代码中 分叉实际上是并行运行还是一个接一个地运行 是什么意思wait NULL 程序创建 n 个子进程 n 通过命令行提供 int main int argc char argv int i pid for i 0 i lt ato
  • 在“www.foo.com”页面上,从“www.example.com”加载的脚本可以向“www.example.com”发送ajax请求吗?

    这是否受到跨域策略的限制 你不能 您只能将请求发送至www foo com
  • Windows 上的 python psutil 拒绝访问

    操作系统 windows专业版 我正在尝试使用 psutil 获取进程列表及其 CPU 使用情况 我以管理员身份运行脚本 但在遇到进程 DymoPnpService exe 时失败 可能是什么问题 import psutil def pro
  • 空派生优化

    大多数 C 程序员都知道空基类优化是一种技术 idiom 空的子班级会发生什么 例如 class EmptyBase int i template
  • C语言中如何对函数进行排序? “函数的先前隐式声明位于此处”错误

    我确信以前有人问过这个问题 但我找不到任何对我有帮助的东西 我有一个带有 C 函数的程序 如下所示 function2 function1 function1 function2 main function1 它比这更复杂 但我正在使用递归
  • 有没有人使用 Microsoft UI Automation 成功实施 UI 测试自动化制度?

    我正在寻找自动化 UI 测试框架 软件工具 过去我一直在使用测试完成 虽然它是一个很好的软件 但是 GUI 测试自动化的概念被认为是足够困难的 所以我写了一些帖子 to complain about it 第三方测试自动化工具的问题之一是您
  • Rails Passenger Glyphicon CORS Cloudfront NGINX 问题

    所以我知道 stackoverflow 上有关于 CORS Nginx Cloudfront 和 Heroku 的这些问题 但由于某种原因我无法让它工作 我一直在关注这个问题的答案 如何使用 Rails nginx 和乘客配置 Access