如何为 nginx 位置指令配置 .ebextensions? [英] How to configure .ebextensions for nginx location directive?

查看:24
本文介绍了如何为 nginx 位置指令配置 .ebextensions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Elastic Beanstalk 中配置我的暂存环境以始终禁止所有蜘蛛.nginx 指令看起来像这样:

I want to configure my staging environment in Elastic Beanstalk to always disallow all spiders. The nginx directive would look like this:

location /robots.txt {
    return 200 "User-agent: *
Disallow: /";
}

我知道我想在 .ebextensions/文件夹下创建一个文件,例如 01_nginx.config,但我不确定如何在其中构建 YAML 以使其正常工作.我的目标是将此位置指令添加到现有配置中,而不必完全替换任何现有的配置文件.

I understand that I would want to create a file under the .ebextensions/ folder, such as 01_nginx.config, but I'm not sure how to structure the YAML inside it such that it would work. My goal is to add this location directive to existing configuration, not have to fully replace any existing configuration files which are in place.

推荐答案

有一种方法在 Amazon Linux 2 上使用更新的 .platform/nginx 配置扩展(而不是旧的 AMI)).

There is an approach which uses the more recent .platform/nginx configuration extension on Amazon Linux 2 (as opposed to older AMIs).

默认的 nginx.conf 在整个 nginx.conf 文件的两个位置包含配置部分.一个直接在 http 块内,所以你不能在这里放置额外的 location 块,因为这在语法上是不合法的.不过,第二个在 server 块内,这正是我们所需要的.

The default nginx.conf includes configuration partials in two locations of the overall nginx.conf file. One is immediately inside the http block, so you can't place additional location blocks here, because that's not syntactically legal. The second is inside the server block, though, and that's what we need.

第二个位置的部分文件包含在一个特殊的子目录 .platform/nginx/conf.d/elasticbeanstalk 中.将您的位置片段放在这里以添加位置块,如下所示:

This second location's partial files are included from a special sub-directory, .platform/nginx/conf.d/elasticbeanstalk. Place your location fragment here to add location blocks, like so:

# .platform/nginx/conf.d/elasticbeanstalk/packs.conf
location /packs {
    alias /var/app/current/public/packs;
    gzip_static on;
    gzip on;
    expires max;
    add_header Cache-Control public;
}

这篇关于如何为 nginx 位置指令配置 .ebextensions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆