红色警报[AWS]

时间:2015-07-09 17:20:26

标签: apache .htaccess amazon-web-services url-rewriting elastic-beanstalk

简而言之,我希望能够使用htaccess,以便我可以执行各种重写命令。我正在使用AWS elasticbeanstalk,下面是我试图让htaccess工作时的困境。

我的实例未能上传,并且已收到红色警报,如下图所示: enter image description here

基本上我使用.ebextensions覆盖所有内容以允许htaccess使用以下代码:

files:          
  "/etc/httpd/conf.d/enable_mod_rewrite.conf": 
     mode: "644"
     owner: root
     group: root
     content: |
       AllowOverride All

但这不是造成问题的原因。运行问题是:

RewriteEngine On

位于htaccess。几乎不能接受重写和开启。

更新

在/var/log/eb-activity.log中:

Command CMD-TailLogs succeeded.
[2015-07-10T10:25:09.784Z] INFO  [25589] - [CMD-TailLogs] : Starting activity...
[2015-07-10T10:25:10.206Z] INFO  [25589] - [CMD-TailLogs/AddonsBefore] : Starting activity...
[2015-07-10T10:25:10.207Z] INFO  [25589] - [CMD-TailLogs/AddonsBefore] : Completed activity.
[2015-07-10T10:25:10.207Z] INFO  [25589] - [CMD-TailLogs/TailLogs] : Starting activity...
[2015-07-10T10:25:10.207Z] INFO  [25589] - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...

在/var/log/eb-commandprocessor.log

   [2015-07-10T10:37:19.644Z] DEBUG [25873] : Checking if the command processor should execute...
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Checking whether the command is applicable to instance (i-80bbbd77)..
[2015-07-10T10:37:19.645Z] INFO  [25873] : Command is applicable to this instance (i-80bbbd77)..
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Checking if the received command stage is valid..
[2015-07-10T10:37:19.645Z] INFO  [25873] : No stage_num in command. Valid stage..
[2015-07-10T10:37:19.645Z] INFO  [25873] : Command processor should execute command.
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Storing current stage..
[2015-07-10T10:37:19.645Z] DEBUG [25873] : Stage_num does not exist. Not saving null stage. Returning..
[2015-07-10T10:37:19.646Z] INFO  [25873] : Executing command: CMD-TailLogs...
[2015-07-10T10:37:19.646Z] DEBUG [25873] : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2015-07-10T10:37:19.647Z] DEBUG [25873] : Refreshing metadata..
[2015-07-10T10:37:20.061Z] DEBUG [25873] : Refreshed environment metadata.
[2015-07-10T10:37:20.061Z] DEBUG [25873] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent||commands..
[2015-07-10T10:37:20.062Z] DEBUG [25873] : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2015-07-10T10:37:20.064Z] INFO  [25873] : Found enabled addons: ["logpublish"].
[2015-07-10T10:37:20.066Z] INFO  [25873] : Updating Command definition of addon logpublish.
[2015-07-10T10:37:20.066Z] DEBUG [25873] : Loaded definition of Command CMD-TailLogs.
[2015-07-10T10:37:20.066Z] INFO  [25873] : Executing command CMD-TailLogs activities...
[2015-07-10T10:37:20.066Z] DEBUG [25873] : Setting environment variables..
[2015-07-10T10:37:20.066Z] INFO  [25873] : Running AddonsBefore for command CMD-TailLogs...
[2015-07-10T10:37:20.067Z] DEBUG [25873] : Running stages of Command CMD-TailLogs from stage 0 to stage 0...
[2015-07-10T10:37:20.067Z] INFO  [25873] : Running stage 0 of command CMD-TailLogs...
[2015-07-10T10:37:20.067Z] DEBUG [25873] : Loaded 1 actions for stage 0.
[2015-07-10T10:37:20.067Z] INFO  [25873] : Running 1 of 1 actions: TailLogs...

更新我的.htaccess文件的内容

RewriteEngine On
RewriteCond %{THE_REQUEST} /searchPage.php\?crs_category=([^\s]+) [NC]
RewriteRule ^ category/%1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([^/]+)/?$  searchPage.php?crs_category=$1 [QSA,L,NC]

1 个答案:

答案 0 :(得分:4)

  

AllowOverride仅在指定的<Directory>部分有效   没有正则表达式,不在<Location><DirectoryMatch>   或<Files>部分。

     

来源:Apache Core Module

您将AllowOverride放入/etc/httpd/conf.d/enable_mod_rewrite.conf。这可能会导致Apache无法启动。

我刚尝试使用默认的Elastic Beanstalk示例PHP配置(请参阅Supported PlatformsSample Application)。我还在示例PHP应用程序中添加了两个新文件:

<强> phpinfo.php

<?php
    phpinfo();

<强> .htaccess

RewriteEngine on
RewriteRule ^/?info.html$ phpinfo.php [L]

结果是:

PHPInfo was displayed correctly using <code>mod_rewrite</code> /info.html

默认情况下,Elastic Beanstalk PHP环境已经将mod_rewriteAllowOverride All启用到PHP应用程序目录。

我还尝试添加您的.ebextensions脚本(添加)。

files:             "/etc/httpd/conf.d/enable_mod_rewrite.conf": 
     mode: "644"
     owner: root
     group: root
     content: |
       AllowOverride All

部署后,Apache服务器无法启动,无法访问Web。这是由错误的配置引起的。错误是我在答案中已经说过了。

解决方案可能是删除enable_mod_rewrite.conf并使用默认环境。

<强>更新

我尝试使用简单的searchPage.php和您的.htaccess,但经过一点修改,您在第二行^category之间有一个额外的空格。< / p>

<强> .htaccess

RewriteEngine On
RewriteCond %{THE_REQUEST} searchPage.php\?crs_category=([^\s]+) [NC]
RewriteRule ^category/$1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([^/]+)/?$ searchPage.php?crs_category=$1 [QSA,L,NC]

<强> searchPage.php

<?php
    header('Content-Type: text/plain');
    print_r($_SERVER);
    print_r($_REQUEST);

我试着做一个卷曲:

$ curl -v 'http://default-environment-zjqxqumicq.elasticbeanstalk.com/searchPage.php?crs_category=test'

* Hostname was NOT found in DNS cache
*   Trying 54.173.237.116...
* Connected to default-environment-zjqxqumicq.elasticbeanstalk.com (54.173.237.116) port 80 (#0)
> GET /searchPage.php?crs_category=test HTTP/1.1
> User-Agent: curl/7.35.0
> Host: default-environment-zjqxqumicq.elasticbeanstalk.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=UTF-8
< Date: Tue, 21 Jul 2015 13:27:56 GMT
* Server Apache is not blacklisted
< Server: Apache
< Content-Length: 1490
< Connection: keep-alive
< 
Array
(
    [PHP_MEMORY_LIMIT] => 256M
    [PHP_MAX_EXECUTION_TIME] => 60
    [PHP_DISPLAY_ERRORS] => Off
    [PHP_COMPOSER_OPTIONS] => 
    [PHP_ALLOW_URL_FOPEN] => On
    [PHP_ZLIB_OUTPUT_COMPRESSION] => Off
    [PHP_DOCUMENT_ROOT] => /
    [PHP_DATE_TIMEZONE] => UTC
    [HTTP_HOST] => default-environment-zjqxqumicq.elasticbeanstalk.com
    [HTTP_ACCEPT] => */*
    [HTTP_USER_AGENT] => curl/7.35.0
    [HTTP_X_FORWARDED_FOR] => 149.129.122.128
    [HTTP_X_FORWARDED_PORT] => 80
    [HTTP_X_FORWARDED_PROTO] => http
    [HTTP_CONNECTION] => keep-alive
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache
    [SERVER_NAME] => default-environment-zjqxqumicq.elasticbeanstalk.com
    [SERVER_ADDR] => 172.31.5.238
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 172.31.30.235
    [DOCUMENT_ROOT] => /var/www/html/
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] => 
    [CONTEXT_DOCUMENT_ROOT] => /var/www/html/
    [SERVER_ADMIN] => root@localhost
    [SCRIPT_FILENAME] => /var/www/html/searchPage.php
    [REMOTE_PORT] => 24890
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => crs_category=test
    [REQUEST_URI] => /searchPage.php?crs_category=test
    [SCRIPT_NAME] => /searchPage.php
    [PHP_SELF] => /searchPage.php
    [REQUEST_TIME_FLOAT] => 1437485276.635
    [REQUEST_TIME] => 1437485276
)
Array
(
    [crs_category] => test
)
* Connection #0 to host default-environment-zjqxqumicq.elasticbeanstalk.com left intact

$ curl -v 'http://default-environment-zjqxqumicq.elasticbeanstalk.com/category/test'                   

* Hostname was NOT found in DNS cache
*   Trying 52.5.119.104...
* Connected to default-environment-zjqxqumicq.elasticbeanstalk.com (52.5.119.104) port 80 (#0)
> GET /category/test HTTP/1.1
> User-Agent: curl/7.35.0
> Host: default-environment-zjqxqumicq.elasticbeanstalk.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=UTF-8
< Date: Tue, 21 Jul 2015 13:30:13 GMT
* Server Apache is not blacklisted
< Server: Apache
< Content-Length: 1918
< Connection: keep-alive
< 
Array
(
    [REDIRECT_PHP_MEMORY_LIMIT] => 256M
    [REDIRECT_PHP_MAX_EXECUTION_TIME] => 60
    [REDIRECT_PHP_DISPLAY_ERRORS] => Off
    [REDIRECT_PHP_COMPOSER_OPTIONS] => 
    [REDIRECT_PHP_ALLOW_URL_FOPEN] => On
    [REDIRECT_PHP_ZLIB_OUTPUT_COMPRESSION] => Off
    [REDIRECT_PHP_DOCUMENT_ROOT] => /
    [REDIRECT_PHP_DATE_TIMEZONE] => UTC
    [REDIRECT_STATUS] => 200
    [PHP_MEMORY_LIMIT] => 256M
    [PHP_MAX_EXECUTION_TIME] => 60
    [PHP_DISPLAY_ERRORS] => Off
    [PHP_COMPOSER_OPTIONS] => 
    [PHP_ALLOW_URL_FOPEN] => On
    [PHP_ZLIB_OUTPUT_COMPRESSION] => Off
    [PHP_DOCUMENT_ROOT] => /
    [PHP_DATE_TIMEZONE] => UTC
    [HTTP_HOST] => default-environment-zjqxqumicq.elasticbeanstalk.com
    [HTTP_ACCEPT] => */*
    [HTTP_USER_AGENT] => curl/7.35.0
    [HTTP_X_FORWARDED_FOR] => 149.129.122.128
    [HTTP_X_FORWARDED_PORT] => 80
    [HTTP_X_FORWARDED_PROTO] => http
    [HTTP_CONNECTION] => keep-alive
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache
    [SERVER_NAME] => default-environment-zjqxqumicq.elasticbeanstalk.com
    [SERVER_ADDR] => 172.31.5.238
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 172.31.11.66
    [DOCUMENT_ROOT] => /var/www/html/
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] => 
    [CONTEXT_DOCUMENT_ROOT] => /var/www/html/
    [SERVER_ADMIN] => root@localhost
    [SCRIPT_FILENAME] => /var/www/html/searchPage.php
    [REMOTE_PORT] => 16148
    [REDIRECT_QUERY_STRING] => crs_category=test
    [REDIRECT_URL] => /category/test
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => crs_category=test
    [REQUEST_URI] => /category/test
    [SCRIPT_NAME] => /searchPage.php
    [PHP_SELF] => /searchPage.php
    [REQUEST_TIME_FLOAT] => 1437485413.02
    [REQUEST_TIME] => 1437485413
)
Array
(
    [crs_category] => test
)
* Connection #0 to host default-environment-zjqxqumicq.elasticbeanstalk.com left intact

这很有用。