openresty
Windows版宝塔面板是不支持openresty的,看了宝塔的代码后发现,可以下载openresty的压缩包(下载地址: ),除去conf目录外,直接覆盖其他文件和目录。
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;
并找到conf目录下的fastcgi_params文件,将其中SCRIPT_NAME行的代码改为如下:
fastcgi_param SCRIPT_NAME $real_script_name;
修改后,记得去重启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);
}
}
完。