简体   繁体   English

Azure PHP 应用服务在登录操作时重定向

[英]Azure PHP App Service redirects on login action

Trying to learn more about other languages and Cloud, I downloaded An open source application written in PHP to run it on Azure: FoOlSlide2 .为了进一步了解其他语言和云,我下载了一个用 PHP 编写的开源应用程序以在 Azure 上运行它: FoOlSlide2 It is also known that it runs without problem on XAMPP or WAMPP.众所周知,它在 XAMPP 或 WAMPP 上运行没有问题。

I was able to set up all App environment, create and connect a MySql database and run the app and play its method to install and configure the database without problems.我能够设置所有应用程序环境,创建并连接一个MySql数据库并运行该应用程序并播放其安装和配置数据库的方法没有问题。

But every time when I try to login with valid credentials, it is not able to login me, just redirects me to the login page again.但是每次当我尝试使用有效凭据登录时,它都无法登录我,只是再次将我重定向到登录页面。 But when I try to input invalid credentials, there is not http redirect and also I receive feedback about the invalid attempt.但是当我尝试输入无效凭据时,没有 http 重定向,并且我收到有关无效尝试的反馈。

Doing some searches like here , it makes me think if could be a rewrite configuration error , since had to convert a .htaccess into a web.config file. 像这里这样进行一些搜索,这让我觉得if could be a rewrite configuration error ,因为必须将.htaccess转换为web.config文件。 Although, I did it using own IIS URL Rewrite to generate my rules and also tried online tools to make this conversion for me, but none of those worked.虽然,我使用自己的 IIS URL Rewrite 来生成我的规则,并尝试使用在线工具为我进行此转换,但这些都不起作用。

I tried also to find some option inside Azure Portal - App Services, that could be troubleshooting a login action, without success.我还尝试在 Azure 门户 - 应用服务中找到一些选项,这可能对登录操作进行故障排除,但没有成功。 Php version is compatible with the project (5.6), and the App connects successfully with the database since its setup requires it and created all tables needed. Php 版本与项目(5.6)兼容,并且应用程序成功连接到数据库,因为它的设置需要它并创建了所有需要的表。

Bellow, all relevant info that I think could be used to discover the issue, and also I can provide more if necessary.波纹管,我认为可以用来发现问题的所有相关信息,如果需要,我也可以提供更多信息。

Login Attempt Scenery w/ Invalid Credentials (working as expected):使用无效凭据登录尝试风景(按预期工作):

Request URL: https://xxxxxxxxxxxxx/account/auth/login/
Request Method: POST
Status Code: 200 OK
[...] Error response inside 

Login Attempt Scenery w/ Valid Credentials ( Not working as expected):使用有效凭据登录尝试风景(未按预期工作):

Request URL: https://xxxxxxxxxxxxx/account/auth/login/
Request Method: POST
Status Code: 302 Moved Temporarily
[Header] Location: https://xxxxxxxxxxxxx/account/profile/

Request URL: https://xxxxxxxxxxxxx/account/profile/
Request Method: POST
Status Code: 302 Moved Temporarily
[Header] Location: https://xxxxxxxxxxxxx/account/auth/login/

Request URL: https://xxxxxxxxxxxxx/account/auth/login/
Request Method: GET
Status Code: 200 OK
[Here I am back to login form even inputted valid credentials]

My whole web.config (rules generated using IIS URL Rewriter):我的整个 web.config(使用 IIS URL Rewriter 生成的规则):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{R:1}" pattern="^(index\.php|assets|content|robots\.txt|favicon\.ico)" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="./index.php?{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>  
    <httpProtocol>
  <customHeaders>
    <remove name="ETag"/>
    <add name="Access-Control-Allow-Origin" value="*"/>
    <add name="X-UA-Compatible" value="IE=Edge,chrome=1"/>
    <remove name="X-Powered-By"/>
    <add name="Cache-Control" value="max-age=691200" />
  </customHeaders>
</httpProtocol>
<defaultDocument>
  <files>
    <clear />
    <add value="index.php" />
  </files>
</defaultDocument>
</system.webServer>
</configuration>

.htacess file from GitHub (who I used to generate my web.config rules)来自 GitHub 的 .htacess 文件(我用来生成我的 web.config 规则)

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|content|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

** Updating with more info: ** ** 更新更多信息:**

I also tried to deploy another App Service in Azure, again in PHP, called MangaReader and also open source and that works fine in WAMPP / XAMPP.我还尝试在 Azure 中部署另一个应用服务,同样是在 PHP 中,称为MangaReader并且也是开源的,并且在 WAMPP / XAMPP 中运行良好。 I am also having similar issues regarding login attempts - not redirect itself, but a successful status code without auth.我也有关于登录尝试的类似问题 - 不是重定向本身,而是没有身份验证的成功状态代码。

As before, I generated the web.config file using IIS URL Rewriter based on .htaccess file;和以前一样,我使用基于 .htaccess 文件的 IIS URL Rewriter 生成了 web.config 文件; and also was able to configure all database and ran the site setup.并且还能够配置所有数据库并运行站点设置。 After that, my small doubt about to be a project error has gone.在那之后,我对项目错误的小怀疑就消失了。

It looks so to be:看起来是这样的:

  • A error while converting .htaccess file into web.config;将 .htaccess 文件转换为 web.config 时出错;
  • Some missing configuration inside Azure Portal App Service; Azure 门户应用服务中缺少一些配置;
  • Some missing configuration on IIS; IIS 上缺少一些配置;
  • Any unknown error.任何未知错误。

** Edit 2, Aditional info ** ** 编辑 2,附加信息 **

The issue itself is not about to manage sessions based on .php files, since FoOlSlide2 and MangaReader (both mentioned beforely) does it in a mysql table.问题本身并不是要管理基于 .php 文件的会话,因为 FoOlSlide2 和 MangaReader(前面都提到过)是在 mysql 表中进行的。 Also, FoOlSlide2 has a load balance feature to deal with great quantity of requests (scaling horizontally)此外,FoOlSlide2 具有负载平衡功能来处理大量请求(水平扩展)

Manage the sessions via a database instead of a PHP file.通过数据库而不是 PHP 文件管理会话。 Azure is very wonky and I find this to be the best get-around. Azure 非常不稳定,我发现这是最好的解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM