从nginx中删除perl

iszxjhcz  于 2024-01-06  发布在  Nginx
关注(0)|答案(1)|浏览(204)

我有一个类似这样的nginx块,我想在hello/world请求上运行一个perl脚本。整个设置都在docker中。
我的nginx.conf:

  1. http {
  2. perl_modules perl/lib;
  3. server {
  4. listen 80;
  5. location /hello/world {
  6. perl rewrite.pl;
  7. }
  8. }

字符串
我的docker-compose有这个:

  1. nginx:
  2. image: nginx:perl
  3. ports:
  4. - "8080:80"
  5. volumes:
  6. - ./nginx.conf:/etc/nginx/nginx.conf
  7. - ./rewrite.pl:/etc/nginx/rewrite.pl


然而,当我向/hello/world发出请求时,我在nginx中得到了一个500错误:call_sv(“rewrite.pl“)failed:“Undefined subroutine &main::rewrite.pl called."
有什么可能的吗?

kgsdhlau

kgsdhlau1#

它需要Perl表达式,而不是文件名。
实际上,我怀疑执行文件(可以使用do完成)是不好的,因为我怀疑它会污染重用的名称空间。
你应该把代码移到一个模块中,然后在配置文件中使用use MyModule::mysub来调用模块的mysub
(记住,模块需要有.pm扩展名,并且它必须有一个与其文件名匹配的package指令。

相关问题