小程序云应用支持部署PHP框架的小程序应用,确保您要部署的小程序应用满足云应用的要求。

PHP框架应用配置要求

部署PHP框架的应用,需要满足以下要求:

  • 软件包格式:.zip文件,且源文件打包到.zip文件的根目录
  • 监听端口:9000
  • 默认的web server路径是/public。如需修改路径,例如改为/public_html,可在软件包根目录上创建包含如下内容的_buildpack文件:
     app_entry=public_html
  • 自定义php扩展:扩展安装基于YUM命令,扩展必须在YUM仓库中存在。可在软件包根目录上创建包含如下内容的_buildpack文件(多个扩展用空格分隔):
    php_extensions=php-extesion-name1 php-extension-name2

    扩展安装的日志保存在/home/admin/logs/ext-install-info.log/home/admin/logs/ext-install-err.log中。

自定义Nginx配置测试

小程序云应用通过一层Nginx代理对外提供服务,可以通过在发布包中提供对应环境的Nginx配置文件来自定义Nginx配置。如果没有提供,或文件名称不符,则自动使用默认的配置。

您可以在上传的发布包的根目录创建一个nginx目录,目录下的nginx-test.conf文件以及nginx-prod.conf文件将分别作为为测试环境和生产环境的nginx配置文件。

测试环境默认配置:

#user nginx;
worker_processes  1;

error_log /home/admin/logs/nginx-error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    sendfile        on;
    keepalive_timeout  65;

    #gzip on;

    server {
        listen       80;
        server_name  localhost;
        set $root_path /home/admin/app-run/app_entry;
        root $root_path;
        index  index.php index.html;

        location / {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
        }
        location ~ \.php$ {
        try_files $uri =404;
            #root           html;
            #fastcgi_pass   unix:/var/run/php5-fpm.sock;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

生产环境默认配置:

worker_processes  1;
error_log /home/admin/logs/nginx-error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       443;
        server_name  localhost;

        set $root_path /home/admin/app-run/app_entry;
        root $root_path;
        index  index.php index.html;

        ssl on;
        ssl_certificate  /home/admin/sslcert/cert.pem;
        ssl_certificate_key /home/admin/sslcert/cert.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
        }
        location ~ \.php$ {
        try_files $uri =404;
            #root           html;
            #fastcgi_pass   unix:/var/run/php5-fpm.sock;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }
    # 80 to 443
    server {
        listen       80;
        server_name  127.0.0.1:8080;
        rewrite ^(.*)$ https://$host$1 permanent;
    }
}