How to remove some Apache settings from Amazon Elastic Beanstalk?

时间:2021-08-16 11:46:07

I have a strange issue with Elastic Beanstalk. I deployed a Django project to an auto-scalling EC2 instances.

我对Elastic Beanstalk有一个奇怪的问题。我将Django项目部署到自动缩减的EC2实例。

In the .ebextensions directory I had a python.config file with these lines at the end:

在.ebextensions目录中,我有一个python.config文件,最后包含以下行:

option_settings:
  "aws:elasticbeanstalk:application:environment":
    DJANGO_SETTINGS_MODULE: "myapp.settings_eb_staging"
    "PYTHONPATH": "/opt/python/current/app/django-myapp:$PYTHONPATH"
  "aws:elasticbeanstalk:container:python":
    WSGIPath: myapp/wsgi.py
    NumProcesses: 3
    NumThreads: 20
  "aws:elasticbeanstalk:container:python:staticfiles":
    "/static/": "myapp/static/"
    "/favicon.ico": "myapp/static/site/img/favicon.ico"

When I deployed the project with

当我部署项目时

$ eb deploy

the deployment process created this Apache configuration which can be found at /etc/httpd/conf.d/wsgi.conf:

部署过程创建了这个Apache配置,可以在/etc/httpd/conf.d/wsgi.conf中找到:

Alias /favicon.ico /opt/python/current/app/myapp/static/site/img/favicon.ico
<Directory /opt/python/current/app/myapp/static/site/img/favicon.ico>
Order allow,deny
Allow from all
</Directory>

This was obviously wrong, because the favicon.ico is a file, not a directory.

这显然是错误的,因为favicon.ico是一个文件,而不是目录。

So I tried to remove the last line from python.config file:

所以我试图从python.config文件中删除最后一行:

"/favicon.ico": "myapp/static/site/img/favicon.ico"

and then redeployed the project.

然后重新部署该项目。

The problem is that the Apache directive stays there. I also tried to remove the directive manually, but after the next deploy it appears again. I even tried to rebuild environment, but it still created the wrong Apache configuration directive.

问题是Apache指令停留在那里。我还试图手动删除该指令,但在下次部署后它再次出现。我甚至尝试重建环境,但它仍然创建了错误的Apache配置指令。

How can I get rid of it?

我怎么能摆脱它?

2 个解决方案

#1


0  

It turns out, wsgi.conf configuration file can be overwritten in .ebextensions/python.config file. This is what I did:

事实证明,wsgi.conf配置文件可以在.ebextensions / python.config文件中覆盖。这就是我做的:

  1. SSH to the EC2 instance by eb ssh and get the content of wsgi.conf with cat /etc/httpd/conf.d/wsgi.conf.

    通过eb ssh通过SSH连接到EC2实例,并使用cat /etc/httpd/conf.d/wsgi.conf获取wsgi.conf的内容。

  2. Create a file .ebextensions/wsgi.conf and copy the content of the previous step there. Remove the Apache directives about static directory and favicon.

    创建一个.ebextensions / wsgi.conf文件并复制上一步的内容。删除有关静态目录和favicon的Apache指令。

  3. Modify the .ebextensions/python.config and add a command to copy wsgi.conf to /tmp/ directory (which is probably used during the deployment process):

    修改.ebextensions / python.config并添加命令将wsgi.conf复制到/ tmp /目录(可能在部署过程中使用):

    container_commands:
      01_refresh_apache_conf:
        command: "cp .ebextensions/wsgi.conf /tmp/wsgi.conf"
      02_migrate:
        command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
    leader_only: true
      03_collectstatic:
        command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
    
    option_settings:
      "aws:elasticbeanstalk:application:environment":
        DJANGO_SETTINGS_MODULE: "myapp.settings_eb_staging"
        "PYTHONPATH": "/opt/python/current/app/django-myapp:$PYTHONPATH"
      "aws:elasticbeanstalk:container:python":
        WSGIPath: myapp/wsgi.py
        NumProcesses: 3
        NumThreads: 20
      "aws:elasticbeanstalk:container:python:staticfiles":
        "/static/": "myapp/static/"
    
  4. Commit to git and deploy with eb deploy.

    承诺使用eb deploy进行git和部署。

P.S. to show the favicon from the static directory, I had to add its full path in the base.html template:

附:要显示静态目录中的favicon,我必须在base.html模板中添加其完整路径:

<link rel="shortcut icon" href="{{ STATIC_URL }}site/img/favicon.ico" />

#2


0  

You can just copy your own wsgi.conf (httpd conf) to parent directory and that way your file will be used instead of the default.

您可以将自己的wsgi.conf(httpd conf)复制到父目录,这样就可以使用您的文件而不是默认文件。

container_commands:
  03_wsgireplace:
    command: 'cp . ebextensions/wsgi.conf ../wsgi.conf'

#1


0  

It turns out, wsgi.conf configuration file can be overwritten in .ebextensions/python.config file. This is what I did:

事实证明,wsgi.conf配置文件可以在.ebextensions / python.config文件中覆盖。这就是我做的:

  1. SSH to the EC2 instance by eb ssh and get the content of wsgi.conf with cat /etc/httpd/conf.d/wsgi.conf.

    通过eb ssh通过SSH连接到EC2实例,并使用cat /etc/httpd/conf.d/wsgi.conf获取wsgi.conf的内容。

  2. Create a file .ebextensions/wsgi.conf and copy the content of the previous step there. Remove the Apache directives about static directory and favicon.

    创建一个.ebextensions / wsgi.conf文件并复制上一步的内容。删除有关静态目录和favicon的Apache指令。

  3. Modify the .ebextensions/python.config and add a command to copy wsgi.conf to /tmp/ directory (which is probably used during the deployment process):

    修改.ebextensions / python.config并添加命令将wsgi.conf复制到/ tmp /目录(可能在部署过程中使用):

    container_commands:
      01_refresh_apache_conf:
        command: "cp .ebextensions/wsgi.conf /tmp/wsgi.conf"
      02_migrate:
        command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
    leader_only: true
      03_collectstatic:
        command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
    
    option_settings:
      "aws:elasticbeanstalk:application:environment":
        DJANGO_SETTINGS_MODULE: "myapp.settings_eb_staging"
        "PYTHONPATH": "/opt/python/current/app/django-myapp:$PYTHONPATH"
      "aws:elasticbeanstalk:container:python":
        WSGIPath: myapp/wsgi.py
        NumProcesses: 3
        NumThreads: 20
      "aws:elasticbeanstalk:container:python:staticfiles":
        "/static/": "myapp/static/"
    
  4. Commit to git and deploy with eb deploy.

    承诺使用eb deploy进行git和部署。

P.S. to show the favicon from the static directory, I had to add its full path in the base.html template:

附:要显示静态目录中的favicon,我必须在base.html模板中添加其完整路径:

<link rel="shortcut icon" href="{{ STATIC_URL }}site/img/favicon.ico" />

#2


0  

You can just copy your own wsgi.conf (httpd conf) to parent directory and that way your file will be used instead of the default.

您可以将自己的wsgi.conf(httpd conf)复制到父目录,这样就可以使用您的文件而不是默认文件。

container_commands:
  03_wsgireplace:
    command: 'cp . ebextensions/wsgi.conf ../wsgi.conf'