2

初始职位

我已经在 Mojolicious 论坛上发布了我的问题,但仍在寻找解决方案。

由于各种原因,我试图让我编写的一些 Mojolicious 应用程序在 IIS 上运行。我有一个 7.5 (2k8r2) 和 8.5 (2k12r2) 服务器来测试。

IIS 设置非常基础。我在默认网站下创建了一个新应用程序,将其指向代码,添加了 Perl 处理程序映射,并添加了一个默认文档。该站点的路径是http://server.example.com/sessiontest/

设置并运行站点后,一切都按预期工作,只是会话不工作。我写了一个测试应用程序来测试。在脚本开始时,我正在设置会话:

# Setup sessions
app->secrets(['SessionTest']);
app->sessions->cookie_name('sessiontest');

设置会话变量:

get '/set' => sub {
 my $c = shift;
 
 $c->session(testvar => 1);
 $c->redirect_to('/');
};

并使用助手测试它是否存在:

helper testvar => sub {
 my $c = shift;
 
 if($c->session('testvar')) {
  return 1;
 }
 
 return undef;
};

当我在任一服务器上使用 Morbo 运行代码时,它运行良好并且会话正常工作。但是在 IIS 下我什么也得不到。

我收到的建议之一是查看 cookie 域和 cookie 路径。作为测试,我尝试在服务器的主机文件和服务器 IP 的客户端中设置一个测试域名test.example.com。我他们补充说:

app->sessions->cookie_domain('.example.com');
app->sessions->cookie_path('/sessiontest');

我假设cookie_path应该是'/',我也尝试过但没有运气。

任何帮助,将不胜感激!

IIS 配置

这是一个新安装的运行 IIS 8.5 的 W2k12R2 机器。我安装了 ActivePerl 5.24。配置是我能得到的基本配置。这是我配置 IIS 的步骤。

  • 安装带有 CGI 支持的 IIS
  • 将测试应用复制到 C:\Code\sessiontest\
  • 从默认网站 -> 添加应用程序
  • 别名:sessiontest,物理路径:C:\Code\sessiontest\
  • 选择会话测试应用程序
  • 将 *.pl 的处理程序映射添加到 C:\Perl64\bin\perl.exe "%s" %s
  • 为 app.pl 添加默认文档

卷曲的输出

从 curl 到 IIS 服务器的结果。

curl -I http://server.example.com/sessiontest/app.pl/set
HTTP/1.1 200 OK
Content-Length: 160
Content-Type: text/html;charset=UTF-8
Server: Microsoft-IIS/7.5
[Thu Aug  3 19: 49:38 2017] [debug] HEAD "/"
[Thu Aug  3 19: 49:38 2017] [debug] Routing to a callback
[Thu Aug  3 19: 49:38 2017] [debug] Rendering template "index.html.ep" from DATA section
[Thu Aug  3 19: 49:38 2017] [debug] Rendering template "layouts/default.html.ep" from DATA section
[Thu Aug  3 19: 49:38 2017] [debug] 200 OK (0.002271s, 440.335/s)
Date: Thu, 03 Aug 2017 23:49:38 GMT

与从 Morbo 运行的结果相比

curl -I http://server.example.com:3000/set
HTTP/1.1 302 Found
Content-Length: 0
Date: Thu, 03 Aug 2017 23:51:29 GMT
Location: /
Server: Mojolicious (Perl)
Set-Cookie: sessiontest=eyJleHBpcmVzIjoxNTAxODA3ODg5LCJ0ZXN0dmFyIjoxfQ----96063fca63a3457e89becc55d7df39898466bb99; expires=Fri, 04 Aug 2017 00:51:29 GMT; path=/; HttpOnly

我将模式设置为生产,现在我在 IIS 上更接近了。

curl -I http://server.example.com/sessiontest/app.pl/set
HTTP/1.1 200 OK
Content-Length: 160
Content-Type: text/html;charset=UTF-8
Server: Microsoft-IIS/7.5
Date: Fri, 04 Aug 2017 00:04:30 GMT
4

0 回答 0