在弹性 beantalk 上配置 apache [英] Configure apache on elastic beanstalk

查看:40
本文介绍了在弹性 beantalk 上配置 apache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 django 在 elastic beanstalk 上进行开发,我想对 apache 配置进行两项更改:

I'm developing with django on elastic beanstalk and I want to make two changes to apache configuration:

1.将 www.domain.com 重定向到 domain.com

1. redirect www.domain.com to domain.com

2.将 http://domain.com 重定向到 https://domain.com

我没有 apache 配置的经验,谷歌搜索让我想到我应该将 RewriteRules 放在 .htaccess 文件中.

I don't have experience with apache configuration, googling it gave me the idea that I should put RewriteRules in .htaccess file.

示例:如何在亚马逊上强制使用 https弹性豆茎而不会失败健康检查

我找不到有关如何使用弹性 beanstalk 配置 (.ebextensions) 执行此操作的说明,我尝试简单地将 .htaccess 文件放入我的根文件中并进行部署,但没有成功.

I couldn't find instructions on how to do it with elastic beanstalk configuration (.ebextensions), I tried to simply put a .htaccess file in my root filder and deploy but it didn't work.

有谁知道如何在弹性 beantalk 中添加 RewriteRules?

Does anyone know how it's possible to add the RewriteRules in elastic beanstalk?

推荐答案

这是一个简单的解决方案

this is an easy solution

  1. ssh 进入您的 EC2 实例
  2. 将/etc/httpd/conf.d/wsgi.conf 的内容复制到名为 wsgi.conf 的本地文件中,该文件将放置在您的应用程序的基本文件夹中
  3. 编辑 wsgi.conf 的本地版本,并在 < 中添加以下重定向规则.虚拟主机> 标签

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

  • /status"更改为您用作健康检查页面的任何页面.

  • Change the "/status" to whatever page you are using as a health check page.

    编辑您的 <app>.conf 文件位于您的 .ebextensions 目录中,以添加容器命令以将此版本的 wsgi.conf 复制到 Amazon 的版本上

    Edit your < app>.conf file inside your .ebextensions directory to add a container command to copy this version of wsgi.conf over Amazon’s version

    container_commands:
    01_syncdb:
      command: "django-admin.py syncdb --noinput" leader_only: true
    02_collectstatic:
      command: "django-admin.py collectstatic --noinput"
    03_wsgireplace:
      command: 'cp wsgi.conf /etc/httpd/conf.d/wsgi.conf'
    ...
    

  • 部署代码.

  • Deploy the code.

    它应该可以工作,并且每个部署都会正确更新文件.唯一需要注意的是,如果亚马逊将来更改其基本 wsgi.conf 文件内容,那么您的副本可能不再有效.

    It should work and the file will be properly updated for each deployment. The only thing to watch for is if Amazon changes their base wsgi.conf file contents in the future, then your copy may no longer work.

    来源:rickchristianson

    这篇关于在弹性 beantalk 上配置 apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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