0

“静态”路由我的Python应用程序规则在我的AWS弹性青苗应用程序(和其他地方)行为异常,出现覆盖所有其他规则。例如,使用下面的两个函数,在我的开发机器和其他AWS上的测试服务器上,routes列出最后的静态规则,并且match_route显示其他非静态规则匹配以“static /”开头的路径。 ..'。如预期的那样,如果我导航到在非AWS机器上具有以static/...开头的路径的页面,则会匹配其中一个(非静态)规则。但是,在AWS-EB上,(只有),服务器的静态规则将针对此类路径调用!为什么AWS Elastic Beanstalk Python先于其他所有人优先插入“静态”规则?

为什么以及如何AWS-EB“插入”领先于所有其他人的这个规则?如何在AWS上禁用此行为,或者在我的非AWS系统中复制它?


application.url_map.host_matching = True 
# ... 

def routes(verbose, wide): 
    """List routes supported by the application""" 
    for rule in sorted(app.url_map.iter_rules()): 
     if verbose: 
      fmt = "{:45s} {:30s} {:30s}" if wide else "{:35s} {:25s} {:25s}" 
      line = fmt.format(rule, rule.endpoint, ','.join(rule.methods)) 
     else: 
      fmt = "{:45s}" if wide else "{:35s}" 
      line = fmt.format(rule) 

     print(line) 

def match_route(host, match): 
    """Match a route for a given host""" 
    if match is not None: 
     urls = app.url_map.bind(host) 
     try: 
      m = urls.match(match, "GET") 
      z = '{}({})'.format(m[0], ','.join(["{}='{}'".format(arg, m[1][arg]) for arg in m[1]] + 
               ["host='{}'".format(host)])) 
      return z 
     except NotFound: 
      return 

回答

0

这是Apache服务器配置的/etc/httpd/conf.d/wsgi.conf结果包含

Alias /static/ /opt/python/current/app/static/ 

如果您删除或注释掉该行,该服务器将不再是“拦截”的路径是开始与'静态'。

实现这一然而,有一点麻烦比人们猜测,由于wigs.conf文件获取(重新)创建afterfiles载和commands被执行。解决此

一种方法是修改与部署后钩的文件,应确保一次重启后的web服务器:

files: 
    "/opt/elasticbeanstalk/hooks/appdeploy/post/remalias.sh" : 
    mode: "00775" 
    owner: root 
    group: root 
    content: | 
     sed -i.backup -e 's/^Alias\s[/]static[/]\s[a-z/]*$//g' /etc/httpd/conf.d/wsgi.conf 
     service httpd restart