【问题标题】:Custom nginx config for PHP Elastic Beanstalk environmentPHP Elastic Beanstalk 环境的自定义 nginx 配置
【发布时间】:2017-07-24 03:26:18
【问题描述】:

我有一个使用 PHP 预配置平台的 Web 服务器环境。我想通过 nginx 将请求传递给代理服务器。这是我在.ebextensions/nginx.config 中的内容:

files:
  "/etc/nginx/conf.d/000_my_config.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      server {
        sub.mysite.com;
        listen 80;

        location = / {
          rewrite ^ http://www.google.com;
        }

        location / {
          proxy_pass http://****.elasticbeanstalk.com;
        }
      }

文件/etc/nginx/conf.d/000_my_config.conf 在服务器上创建。当我访问sub.mysite.com 时,我没有被定向到谷歌,而是我的应用程序,所以似乎没有加载 nginx 配置。我已经看到其他答案表明要执行 sudo service nginx reload 来重新启动 nginx,但我得到了 nginx: unrecognized service

【问题讨论】:

  • 问题是我使用的 SW 包在其根目录中有一个 .htaccess 文件,所以 Beanstalk 使用 Apache。我不确定 Beanstalk 上的 PHP 是否可以使用 nginx,但我在 .htaccess 文件语句中添加了 RewriteCondRewriteRule 来做我需要的事情。

标签: php amazon-web-services nginx amazon-elastic-beanstalk


【解决方案1】:

您的服务器在/opt/elasticbeanstalk/support/conf/nginx_config.erb 有文件吗? ElasticBeanstalk 的 Ruby 版本使用该文件来配置 nginx。

如果 PHP 版本相同,那么您应该可以在那里插入您的配置,尽管您希望使用 sed 来执行此操作,而不是安装一个全新的文件。

【讨论】:

  • 我没有该文件。
猜你喜欢
  • 2015-03-27
  • 2020-12-15
  • 2019-01-16
  • 2020-12-08
  • 2014-12-08
  • 2018-08-27
  • 2012-12-13
  • 2015-02-23
  • 2020-08-27
相关资源
最近更新 更多