Adr*_*uez 5 nginx amazon-web-services amazon-elastic-beanstalk
我需要向 nginx.conf 添加一些位置,以便环境 URL 指向 app.php。我已经使用 vi 修改了文件。重启 NGINX 就可以了。但是当我使用eb deploy时,我需要自动加载这个配置。
我已经阅读并尝试过:https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
Elasticbeanstalk 在 Python 的单个实例上配置 HTTPS:模板中不允许使用空值
如何为 nginx 位置指令配置 .ebextensions?
Amazon Elastic Beanstalk ebextension
我有 /.ebextensions/01_nginx.config
files:
"/etc/nginx/nginx.conf":
mode: "0000644"
owner: root
group: root
content: |
My conf file
Run Code Online (Sandbox Code Playgroud)
但是那个配置不起作用。我试过改变“/etc/nginx/nginx.conf”:通过“/etc/nginx/my_nginx.conf”:文件出现了!所以我尝试用我的自定义文件替换默认文件:
container_commands:
deleteConf:
command: "sudo rm /etc/nginx/nginx.conf"
changeConf:
command: "sudo cp /etc/nginx/my_nginx.conf /etc/nginx/nginx.conf"
Run Code Online (Sandbox Code Playgroud)
放置在 01_nginx.config 中的先前配置下方。但是命令不起作用。nginx.conf 没有被我的删除或替换。我做错了什么?
编辑:我读过 .ebextensions 中的文件是按字母顺序评估的。我想知道是否在文件存在之前执行了复制命令。所以我创建了一个新文件 /.ebextensions/02_copy.config 并移到那里
container_commands:
deleteConf:
command: "sudo rm /etc/nginx/nginx.conf"
changeConf:
command: "sudo cp /etc/nginx/my_nginx.conf /etc/nginx/nginx.conf"
Run Code Online (Sandbox Code Playgroud)
没有运气
花了一整天试图修改后nginx.conf有关部署,创建自定义nginx.conf直接的/ etc / nginx的/通过的.config文件.ebextensions 没有工作对我来说,因为它会被默认系统覆盖一。
当我在/tmp 中创建自定义文件并编写一个替换/etc/nginx/nginx.conf的container_command 时,发生了同样的事情。
您实际上需要创建一个脚本,该脚本将在部署后执行,在 elastic beanstalk 写入您的所有文件后。
来源:https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html
要在部署后执行任何脚本,请将以下代码放入.ebextensions根目录下的.config文件中
01_write_custom_ng_conf.config
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
Run Code Online (Sandbox Code Playgroud)
files:
"/tmp/custom_nginx.conf":
mode: "000644"
owner: root
group: root
content: |
# your .conf file
Run Code Online (Sandbox Code Playgroud)
"/opt/elasticbeanstalk/hooks/appdeploy/post/update_ng_conf.sh":
mode: "000644"
owner: root
group: root
content:
#!/usr/bin/bash
sudo mv /tmp/custom_nginx.conf /etc/nginx/nginx.conf
Run Code Online (Sandbox Code Playgroud)
来源:https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
脚本现在从.platform中的子文件夹执行,您必须将其放置在项目的根目录下,如下所示:
~/your-app/
|-- someFile.py
|-- Procfile
|-- readme.md
|-- .ebextensions/
| |-- 01_write_custom_ng_conf.config
`-- .platform/
|-- hooks
`-- postdeploy
`-- 01_update_ng_conf.sh # Executed post deployment
Run Code Online (Sandbox Code Playgroud)
在.ebextensions的根目录创建一个.config文件。
01_write_custom_ng_conf.config
创建修改后的nginx.conf文件并将其放在/tmp 中。
files:
"/tmp/custom_nginx.conf":
mode: "000644"
owner: root
group: root
content: |
# your .conf file
Run Code Online (Sandbox Code Playgroud)
在.platform/hooks/postdeploy 中创建一个小脚本并将权限更改为755。
01_update_ng_conf.sh
#!/usr/bin/bash
# Replace the original nginx.conf by our custom one
sudo mv /tmp/custom_nginx.conf /etc/nginx/nginx.conf
# Restart nginx to apply modifications
sudo service nginx restart
Run Code Online (Sandbox Code Playgroud)
这对我来说在Amazon Linux 2 Python 3.7 环境中非常有效。不确定你的,但这应该是一样的。
确保您的.config文件缩进是完美的,因为解析器并不总是检测到错误,并且不会执行代码。
| 归档时间: |
|
| 查看次数: |
997 次 |
| 最近记录: |