随记:Win10+宝塔+openresty开发环境部署兼排坑

发布一下 0 0

openresty

Windows版宝塔面板是不支持openresty的,看了宝塔的代码后发现,可以下载openresty的压缩包(下载地址: http://openresty.org/cn/download.html),除去conf目录外,直接覆盖其他文件和目录。

随记:Win10+宝塔+openresty开发环境部署兼排坑

pathinfo

Windows10版宝塔面板还有一个坑,就是默认的php pathinfo规则不起作用,需要自行在nginx的配置文件里面去做处理。

对应配置文件的目录在/nginx/conf/php/xx.conf,xx表示php的版本号

将原来的代码:

    fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;    fastcgi_param  PATH_INFO  $fastcgi_path_info;

改成下面的:

    set $real_script_name $fastcgi_script_name;    if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {            set $real_script_name $1;            set $path_info $2;     }    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;    fastcgi_param SCRIPT_NAME $real_script_name;    fastcgi_param PATH_INFO $path_info;

修改后,记得去重启nginx才会生效。另外注意不用去改php.ini文件中的cgi.fix_pathinfo项,有些文章会提到这个,没用的。

执行Lua

新建站点后,如果想要站点能够支持运行lua,还需要在站点的nginx配置文件上加设置:

对应配置文件的目录在/nginx/conf/vhost/xx.conf,xx表示站点域名。

在对应站点的配置文件中添加下面代码:

    # 匹配地址    location ~ ^/([-_a-zA-Z0-9/]+\.lua)(/([-_a-zA-Z0-9/]+)|$)    {        default_type text/html;        # set $real_script_name $1;        # set $path_info $2;        content_by_lua_file $document_root/$1;    }    # 开发环境,关闭Lua代码缓存    lua_code_cache off;

如果自己对路径模式有其他需求,还可以通过下面的代码去测试自己的配置规则写得对不对:

    # 用来测试用匹配地址    location ~ ^/([-_a-zA-Z0-9/]+\.lua)(/([-_a-zA-Z0-9/]+)|$)    {        default_type text/html;        set $match_one $1;        set $match_two $2;        content_by_lua_block {            ngx.say(ngx.var.match_one);            ngx.say(':');            ngx.say(ngx.var.match_two);        }    }

完。

版权声明:内容来源于互联网和用户投稿 如有侵权请联系删除

本文地址:http://0561fc.cn/100061.html