上云无忧 > 文档中心 > 百度智能云应用引擎BAE配置app.conf
应用引擎BAE
百度智能云应用引擎BAE配置app.conf

文档简介:
app.conf是BAE提供的部署配置文件,用户通过配置app.conf提供的如下功能,实现对所托管Web应用的高级定制: handlers: 自定义Web服务器规则 environment: 环境变量 system_packages:安装系统软件包
*此产品及展示信息均由百度智能云官方提供。免费试用 咨询热线:400-826-7010,为您提供专业的售前咨询,让您快速了解云产品,助您轻松上云! 微信咨询
  免费试用、价格特惠

app.conf是BAE提供的部署配置文件,用户通过配置app.conf提供的如下功能,实现对所托管Web应用的高级定制:

  • handlers: 自定义Web服务器规则
  • environment: 环境变量
  • system_packages:安装系统软件包

注意:app.conf须严格遵照YAML语法规范,任何不合规范的配置,如使用中文、Tab或不符合缩进规则等,均会导致部署失败。

handlers

handlers支持如下规则:

  • url与regex_url: 设置路由规则
  • errordoc: 自定义错误页面
  • expire: 设置过期时间
  • mime: 设置某类扩展名对应的文件类型
  • check_exist: 检查文件或目录是否存在

如下为一个简单的app.conf文件handlers示例:

handlers:
  - regex_url : /
    script: index.php
  - regex_url : ^/index\.html$
    script : index.php

  - errordoc : 404 /error/404.html
  - errordoc : 0 /error/default.html

  - expire : .jpg modify 10 years
  - expire : .swf modify 10 years
  - expire : .png modify 10 years
  - expire : .gif modify 10 years
  - expire : .JPG modify 10 years
  - expire : .ico modify 10 years

关于上述规则的解释如下:

  • 指定默认首页为index.php
  • 当访问的URL匹配“/index.html”时,指向“index.php”
  • 对于404错误的提示页面指向“/error/404.html”
  • 对于除了404以外的错误,提示页面指向“/error/default.html”
  • 对于扩展名为.jpg/.swf/.png/.gif/.JPG/.ico的文件,其缓存失效时间为10年

url与regex_url

作用

设置路由规则。当用户输入的URL字符串的子串与“url”所匹配的字符串一致时,执行script指定的操作;“regex-url”规则的功能与“url”规则相同,支持标准正则表达式,可与script、status_code及location规则配合使用,推荐使用regex-url规则。

语法

handlers :
  - url : <Regex>
    script : <File_Path>
  - url : <Regex>
    static_files : <File_Path>
  - regex_url : <Regex>
    script : <File_Path>
  - regex_url : <Regex>
    status_code : {301 | 302 | 403 | 404}
    [location : <Redirection_Page>]

注意:

[location: <Redirection_Page>]仅能在status_code设为301或302时使用。

代码示例

handlers :
  - url : /
    script : home.php
  - url : /index\.html
    script : home.php
  - url : /(aaa)/(.*\.gif)
    static_files : static/$2
  - url : /admin/.* 
    script : admin.php
  - regex_url : ^/[a-z0-9]*\.html$
    script : /index.php       
  - regex_url : ^/secure_page$
    status_code : 403
  - regex_url : ^/secure_page$
    status_code : 302
    location : http://example.com/error.htm
示例 解释
- url : /
  script : home.php
指定默认首页为home.php
- url : /index.html
  script : home.php
当访问的URL包含“/index.html”时,指向home.php
- url : /(aaa)/(.*.gif)
  static_files : static/$2
当访问的URL包含“/aaa/xxx.gif”时,指向“static/xxx.gif”,其中“xxx”为不包含换行在内的任意字符串
- url : /admin/.*
  script : admin.php
当访问的URL包含“/admin/xxx”时,指向“admin.php”,其中“xxx”为不包含换行在内的任意字符串
- regex_url : ^/[a-z0-9]*.html$
  script : /index.php
当访问的URL匹配“/xxx.html”时,指向“index.php”,其中“xxx”必须为小写字母或者数字。
- regex_url : ^/secure_page$
  status_code : 403
当访问的URL匹配“/secure_page”时,返回403错误。
- regex_url : ^/secure_page$
  status_code : 302
  location : http://example.com/error.html
当访问的URL匹配“/secure_page”时,返回302错误,并转移至http://example.com/error.html

errordoc

  • 作用

    自定义错误页面,设定Web服务器在处理用户请求发生错误时所返回的错误页面。

  • 语法

    handlers :
        - errordoc : <Error_Code> <Error_Response_Page>

    注意:

    <Error_Code>为“0”时表示任意错误。

  • 代码示例

    handlers :
        - errordoc : 403 /error/403.html
        - errordoc : 404 /error/404.html
        - errordoc : 0 /error/default.html

expire

  • 作用

    设置过期时间,指导浏览器对其进行缓存和失效操作。

  • 语法

    handlers :
        - expire : <File_Extension> {access | modify} <Number> {years | months | weeks | days |
  •  hours | minutes | seconds}
  • 代码示例

    handlers :
        - expire : .pdf access 1 months

mime

  • 作用

    设置某类扩展名对应的文件类型。

  • 语法

    handlers :
        - mime : <File_Extension> <Content_Type>
  • 代码示例

    handlers :
        - mime: .txt text/plain

check_exist

  • 作用

    检查文件和目录是否存在,并根据判断结果进行处理,可与script、status_code、location规则配合完成使用。

  • 语法

    handlers :
        # 格式一
        - check_exist : {file_exist | dir_exist | not_exist}
          script : <File_Path>  
        # 格式二 
        - check_exist : {file_exist | dir_exist | not_exist}
          status_code : {301 | 302 | 403 | 404}
          [location : <Redirection_Page>]

    注意:

    [location: <redirection_page>]仅能在status_code设为301或302时使用。

  • 代码示例

    # example 1
    handlers :
      - check_exist : not_exist
             script : /index.php   
    
    # example 2
    handlers :
      - check_exist : not_exist
        status_code: 403
    
    # example 3
    handlers :
      - check_exist : not_exist
        status_code : 302
           location : http://example.com/error.html

environment

  • 作用

    用户自定义环境变量。

  • 语法

    environment :
        <Variable_Name> : <Variable_Value>
  • 代码示例

    environment :
        USER_ENV1 : 1000
        USER_ENV2 : "hahaha"

system_packages

  • 作用

    安装系统软件包,bae会对每个软件包执行apt-get install命令。

  • 语法

    system_packages :
        - <Package_Name>
  • 代码示例

    system_packages :
         - make
         - vim

相似文档
  • 由于当前BAE专业版支持的语言只有java、nodejs、php和python,当用户希望选择其它语言实现一些自定义或增强功能时,用户可以使用BAE专业版的自定义镜像功能。自定义镜像功能帮助用户将集成的镜像代码部署到镜像仓库,然后用户可以选择根据镜像创建应用来实现代码中的功能。
  • 多用户访问控制功能实现了多用户协同开发,项目管理者可以基于应用或者环境为其他开发测试人员开放查看、代码管理及部署等权限。项目管理者通过IAM子账号方式进行授权,即在主账号下添加子用户的账号并对子用户进行策略管理,子用户可以通过“IAM用户登录链接”访问主用户的资源。
  • 为什么SVN、Git无法连接? BAE专业版的SVN、Git身份验证采用AK/SK,不是百度登录的用户名和密码。 Git支持浏览器访问吗? 不支持,只能通过工具或命令行下载。 Git上传大文件会失败怎么解决? BAE专业版中Git上传的单个文件大小不能超过40M。
  • 通过WebSSH登录如何执行拷贝和粘贴? Chrome浏览器上通过WebSSH页面登录时,执行拷贝操作时选中内容后使用Ctrl+Shift命令,执行粘贴操作使用Shift+Insert命令。
  • 为什么本地日志会为空? 一般这种情况可能是Container迁移,导致本地文件全部丢失。本地日志的目的是为了临时调试,并不保证完全可靠。 为什么看不到本地日志? 检查如下两方面: 日志路径是否是/home/bae/log?
官方微信
联系客服
400-826-7010
7x24小时客服热线
分享
  • QQ好友
  • QQ空间
  • 微信
  • 微博
返回顶部