如何从Apache身份验证中排除运行状况检查路径

dxpyg8gm  于 2022-11-16  发布在  Apache
关注(0)|答案(1)|浏览(96)

我在AWS ECS中将Apache作为容器运行。我已启用身份验证,但在部署时由于运行状况检查而失败。以下是我的配置
我的健康检查URL是/subscription/ping?m=5&tab=141046123。如何从身份验证中排除此URL。
我尝试了Require expr %{REQUEST_URI} =~ m#^/subscription/ping\?m=5&tab=141046123$#,但没有成功。语法是否有误?

000-默认.conf

<VirtualHost *:80>
  ServerName dev-services.mydomain.com

  ## Vhost docroot
  ##DocumentRoot "/var/www/html/public"
  DocumentRoot "/var/www/services/current/public"

  ## Directories, there should at least be a declaration for /var/www/html/public

  <Directory "/var/www/services/current/public">
    Options -Indexes
    AllowOverride All
    #Require all granted
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
    Require expr %{REQUEST_URI} =~ m#^/subscription/ping\?m=5&tab=141046123$#

  </Directory>
  ServerSignature Off    

  ## Do not log health check url in access log
  SetEnvIf Request_URI "^/elbhealthcheck$" healthcheck_url=1
  SetEnvIf User-Agent "^ELB-HealthChecker" is_healthchecker=1
  SetEnvIf healthcheck_url 0 !is_healthchecker

    SetEnvIf is_healthchecker 1 dontlog

  LogFormat "{ \"logType\":\"accesslog\", \"time\":\"%{%Y-%m-%d}tT%{%T}t.%{msec_frac}tZ\", \"clientIP\":\"%{X-Forwarded-For}i\", \"remote_hostname\":\"%h\", \"remote_logname\":\"%l\", \"host\":\"%V\", \"request\":\"%U\", \"first_req\":\"%r\", \"query\":\"%q\", \"method\":\"%m\", \"status\":\"%>s\", \"userAgent\":\"%{User-agent}i\", \"referer\":\"%{Referer}i\" }" jsoncombine
    ErrorLogFormat "{ \"logType\":\"errorlog\",\"time\":\"%{cu}t\", \"loglevel\" : \"%l\" ,\"module\" : \"%-m\" , \"process_id\" : \"%P\" , \"message\" : \"%M\" }"

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log jsoncombine env=!dontlog

</VirtualHost>
baubqpgj

baubqpgj1#

添加SetEnvIf User-Agent "^ELB-HealthChecker" let_me_inRequire env let_me_in修复了容器的运行状况检查问题

<VirtualHost *:80>

  ServerName dev-services.mydomain.com

  DocumentRoot "/var/www/services/current/public"

  ## Directories, there should at least be a declaration for /var/www/html/public

  SetEnvIf User-Agent "^ELB-HealthChecker" let_me_in
  <Directory "/var/www/services/current/public">
    Options -Indexes
    AllowOverride All
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
    Require env let_me_in
  </Directory>
  
  ServerSignature Off

  ## Do not log health check url in access log
  SetEnvIf Request_URI "^/elbhealthcheck$" healthcheck_url=1
  SetEnvIf User-Agent "^ELB-HealthChecker" is_healthchecker=1
  SetEnvIf healthcheck_url 0 !is_healthchecker

  SetEnvIf is_healthchecker 1 dontlog

  LogFormat "{ \"logType\":\"accesslog\", \"time\":\"%{%Y-%m-%d}tT%{%T}t.%{msec_frac}tZ\", \"clientIP\":\"%{X-Forwarded-For}i\", \"remote_hostname\":\"%h\", \"remote_logname\":\"%l\", \"host\":\"%V\", \"request\":\"%U\", \"first_req\":\"%r\", \"query\":\"%q\", \"method\":\"%m\", \"status\":\"%>s\", \"userAgent\":\"%{User-agent}i\", \"referer\":\"%{Referer}i\" }" jsoncombine
    ErrorLogFormat "{ \"logType\":\"errorlog\",\"time\":\"%{cu}t\", \"loglevel\" : \"%l\" ,\"module\" : \"%-m\" , \"process_id\" : \"%P\" , \"message\" : \"%M\" }"
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log jsoncombine env=!dontlog

</VirtualHost>

相关问题