找不到带有.ebextensions的AWS Elasticbeanstalk中的Nginx配置文件 [英] Configuring nginx config files in AWS elasticbeanstalk with .ebextensions not found

查看:89
本文介绍了找不到带有.ebextensions的AWS Elasticbeanstalk中的Nginx配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自签名SSL启用https到部署在AWS Elastic Beanstalk上的springboot Web服务器后端.我遵循了在线教程和指南,使用新的https-instance.config更改了我的Nginx配置.

I am trying to enable https to my springboot webserver backend deployed on AWS elastic beanstalk with a self-signed SSL. I followed online tutorials and guides to change my nginx config with a new https-instance.config.

files:
  /etc/nginx/conf.d/myconf.conf:
    mode: "conf"
    owner: root
    group: root
    content: |
      # HTTPS server

      server {
        listen 443;
        server_name localhost;

        ssl on;
        ssl_certificate /etc/pki/tls/certs/server.crt;
        ssl_certificate_key /etc/pki/tls/certs/server.key;
        ssl_prefer_server_ciphers on;

        location / {
          proxy_pass  http://localhost:5000;
          proxy_http_version  1.1;
          proxy_set_header  Connection "";
          proxy_set_header  Host  $host;
          proxy_set_header  X-Real-IP  $remote_addr;
          proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
      }

  /etc/pki/tls/certs/server.crt:
    mode: "000400"
    owner: root
    group: root
    content: |
      -----BEGIN CERTIFICATE-----
 mycert
      -----END CERTIFICATE-----
      
  /etc/pki/tls/certs/server.key:
    mode: "000400"
    owner: root
    group: root
    content: |
      -----BEGIN RSA PRIVATE KEY-----
mykey
      -----END RSA PRIVATE KEY-----

  /opt/elasticbeanstalk/hooks/appdeploy/post/03_restart_nginx.sh:
      mode: "000755"
      owner: root
      group: root
      content: |
        #!/usr/bin/env bash
        sudo service nginx restart

当我对自己的实例进行SSH时,无法在conf.d下找到myconf.conf文件.运行 service nginx状态给我

When I ssh to my instance I am unable to find my myconf.conf files under conf.d. Running service nginx status gives me

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/nginx.service.d
           └─nginx.conf
   Active: active (running) since Wed 2020-08-26 03:06:34 UTC; 15min ago
  Process: 28894 ExecStartPost=/bin/sh -c systemctl show -p MainPID nginx.service | cut -d= -f2 > /var/pids/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 28890 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 28887 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 28886 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 28893 (nginx)
   CGroup: /system.slice/nginx.service
           ├─28893 nginx: master process /usr/sbin/nginx
           └─28897 nginx: worker process

Aug 26 03:06:34  systemd[1]: Starting The nginx HTTP and reverse proxy server...
Aug 26 03:06:34 nginx[28887]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Aug 26 03:06:34  nginx[28887]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Aug 26 03:06:34  systemd[1]: Started The nginx HTTP and reverse proxy server.

我错过了什么.这是我关于AWS EBS的第一个项目.

What am I missing out. This is my first project on AWS EBS.

注意:我正在为EBS运行免费的单层实例

Note: I am running the free tier single instance for EBS

推荐答案

您要使用的 nginx 设置(/etc/nginx/conf.d/myconf.conf )用于 Amazon Linux 1 .

The nginx setting you are trying to use (/etc/nginx/conf.d/myconf.conf) is for Amazon Linux 1.

但是您似乎正在使用 Amazon Linux 2 (AL2).因此,您应该使用不同的文件来设置nginx.对于AL2,nginx设置应位于 .platform/nginx/conf.d/中,而不应位于 .ebextentions 中,如

But it seems that you are using Amazon Linux 2 (AL2). Thus you should be using different files for setting nginx. For AL2, the nginx settings should be in .platform/nginx/conf.d/, not in .ebextentions as shown in the docs.

因此,您可以拥有以下 .platform/nginx/conf.d/myconfig.conf 及其内容:

Therefore, you could have the following .platform/nginx/conf.d/myconfig.conf with content:

server {
    listen 443;
    server_name localhost;

    ssl on;
    ssl_certificate /etc/pki/tls/certs/server.crt;
    ssl_certificate_key /etc/pki/tls/certs/server.key;
    ssl_prefer_server_ciphers on;

    location / {
      proxy_pass  http://localhost:5000;
      proxy_http_version  1.1;
      proxy_set_header  Connection "";
      proxy_set_header  Host  $host;
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

以上只是配置文件的示例.我无法验证该设置是否真正起作用,但是您肯定使用了错误的文件夹来在AL2中设置nginx选项.

The above is an example only of the config file. I can't verify if the setting will actually work, but you are definitely using wrong folders to set nginx options in AL2.

我的建议是尝试首先使其通过ssh手动工作.如果您没有提供自己的 .platform/nginx/nginx.conf 文件,则可能无法覆盖整个nginx设置.

My recommendation would be to try to make it work manually through ssh first. You may find that you need to overwrite entire nginx setting if nothing works by providing your own .platform/nginx/nginx.conf file.

这篇关于找不到带有.ebextensions的AWS Elasticbeanstalk中的Nginx配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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