针对 Azure 中 Web 应用的开源技术常见问题的解答Open-source technologies FAQs for Web Apps in Azure

本文对 Azure App Service Web 应用功能开源技术常见问题 (FAQ) 进行了解答。This article has answers to frequently asked questions (FAQs) about issues with open-source technologies for the Web Apps feature of Azure App Service.

如果本文未解决你的 Azure 问题,请访问 MSDN 和 CSDN 上的 Azure 论坛。If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and CSDN. 可以在这些论坛上发布问题。You can post your issue in these forums. 还可提交 Azure 支持请求。You also can submit an Azure support request. 若要提交支持请求,请在 Azure 支持页上提交。To submit a support request, on the Azure support page.

如何启用 PHP 日志记录以便对 PHP 问题进行故障排除?How do I turn on PHP logging to troubleshoot PHP issues?

若要启用 PHP 日志记录:To turn on PHP logging:

  1. 登录到 Kudu 网站 (https://*yourwebsitename*.scm.chinacloudsites.cn)。Sign in to your Kudu website (https://*yourwebsitename*.scm.chinacloudsites.cn).
  2. 在顶部菜单中,选择“调试控制台” > “CMD”。In the top menu, select Debug Console > CMD.
  3. 选择“Site”文件夹。Select the Site folder.
  4. 选择“wwwroot”文件夹。Select the wwwroot folder.
  5. 选择“+”图标,然后选择“新建文件”。Select the + icon, and then select New File.
  6. 将文件名称设置为“.user.ini”。Set the file name to .user.ini.
  7. 选择“.user.ini”旁边的铅笔图标。Select the pencil icon next to .user.ini.
  8. 在文件中,添加以下代码:log_errors=onIn the file, add this code: log_errors=on
  9. 选择“保存” 。Select Save.
  10. 选择“wp-config.php”旁边的铅笔图标。Select the pencil icon next to wp-config.php.
  11. 将文本更改为以下代码:Change the text to the following code:
    //Enable WP_DEBUG modedefine('WP_DEBUG', true);//Enable debug logging to /wp-content/debug.logdefine('WP_DEBUG_LOG', true);
    //Suppress errors and warnings to screendefine('WP_DEBUG_DISPLAY', false);//Suppress PHP errors to screenini_set('display_errors', 0);
    
  12. 在 Azure 门户中的 Web 应用菜单中,重启 Web 应用。In the Azure portal, in the web app menu, restart your web app.

有关详细信息,请参阅启用 WordPress 错误日志For more information, see Enable WordPress error logs.

如何在应用服务中承载的应用中记录 Python 应用程序错误?How do I log Python application errors in apps that are hosted in App Service?

如果 Python 在启动应用程序时遇到错误,只只会返回简单的错误页(例如“由于发生内部服务器错误,无法显示该页。”)。If Python encounters an error while starting your application, only a simple error page will be returned (e.g. "The page cannot be displayed because an internal server error has occurred.").

捕获 Python 应用程序错误:To capture Python application errors:

  1. 在 Azure 门户中的 Web 应用中,选择“设置” 。In the Azure portal, in your web app, select Settings.
  2. 在“设置” 选项卡上,选择“应用程序设置” 。On the Settings tab, select Application settings.
  3. 在“应用设置” 下,输入以下键/值对:Under App settings, enter the following key/value pair:
    • 键:WSGI_LOGKey : WSGI_LOG
    • 值:D:\home\site\wwwroot\logs.txt(输入所选文件名)Value : D:\home\site\wwwroot\logs.txt (enter your choice of file name)

现在应可在 wwwroot 文件夹中的 logs.txt 文件中看到错误。You should now see errors in the logs.txt file in the wwwroot folder.

如何更改应用服务中承载的 Node.js 应用程序的版本?How do I change the version of the Node.js application that is hosted in App Service?

若要更改 Node.js 应用程序的版本,可以使用以下选项之一:To change the version of the Node.js application, you can use one of the following options:

  • 在 Azure 门户中,使用“应用设置”。In the Azure portal, use App settings.

    1. 在 Azure 门户中,转到自己的 Web 应用。In the Azure portal, go to your web app.
    2. 在“设置”边栏选项卡上,选择“应用程序设置”。On the Settings blade, select Application settings.
    3. 在“应用设置”中,可将 WEBSITE_NODE_DEFAULT_VERSION 包括为键,并将所需的 Node.js 版本作为值。In App settings, you can include WEBSITE_NODE_DEFAULT_VERSION as the key, and the version of Node.js you want as the value.
    4. 转到 Kudu 控制台 (https://*yourwebsitename*.scm.chinacloudsites.cn)。Go to your Kudu console (https://*yourwebsitename*.scm.chinacloudsites.cn).
    5. 若要检查 Node.js 版本,请输入以下命令:To check the Node.js version, enter the following command:
      node -v
      
  • 修改 iisnode.yml 文件。Modify the iisnode.yml file. 更改 iisnode.yml 文件中的 Node.js 版本将仅设置该 iisnode 使用的运行时环境。Changing the Node.js version in the iisnode.yml file only sets the runtime environment that iisnode uses. 你的及其他 Kudu cmd 仍使用在 Azure 门户中的“应用设置”中设置的 Node.js 版本。Your Kudu cmd and others still use the Node.js version that is set in App settings in the Azure portal.

    若要手动设置 iisnode.yml,请在应用根文件夹中创建一个 iisnode.yml 文件。To set the iisnode.yml manually, create an iisnode.yml file in your app root folder. 在该文件中,包括以下行:In the file, include the following line:

    nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\5.9.1\node.exe"
    
  • 在源控件部署期间通过使用 package.json 设置该 iisnode.yml 文件。Set the iisnode.yml file by using package.json during source control deployment. Azure 源控件部署过程包含以下步骤:The Azure source control deployment process involves the following steps:

    1. 将内容移动到 Azure web 应用。Moves content to the Azure web app.
    2. 如果在 Web 应用根文件夹中没有默认部署脚本,则创建一个(deploy.cmd、.deployment 文件)。Creates a default deployment script, if there isn’t one (deploy.cmd, .deployment files) in the web app root folder.
    3. 如果提及 package.json 文件 > 引擎 "engines": {"node": "5.9.1","npm": "3.7.3"} 中的 Node.js 版本,请运行在其中创建 iisnode.yml 文件的部署脚本Runs a deployment script in which it creates an iisnode.yml file if you mention the Node.js version in the package.json file > engine "engines": {"node": "5.9.1","npm": "3.7.3"}
    4. 该 iisnode.yml 文件具有以下代码行:The iisnode.yml file has the following line of code:
      nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\5.9.1\node.exe"
      

我在应用服务中承载的我的 WordPress 应用中看到消息“建立数据库连接时出错”。I see the message "Error establishing a database connection" in my WordPress app that's hosted in App Service. 如何解决此问题?How do I troubleshoot this?

如果在 Azure WordPress 应用中看到此错误,则若要启用 php_errors.log 和 debug.log,请完成启用 WordPress 错误日志中详细介绍的步骤。If you see this error in your Azure WordPress app, to enable php_errors.log and debug.log, complete the steps detailed in Enable WordPress error logs.

启用日志后,重现错误,然后检查日志以了解是否耗尽连接:When the logs are enabled, reproduce the error, and then check the logs to see if you are running out of connections:

[09-Oct-2015 00:03:13 UTC] PHP Warning: mysqli_real_connect(): (HY000/1226): User ‘abcdefghijk79' has exceeded the ‘max_user_connections’ resource (current value: 4) in D:\home\site\wwwroot\wp-includes\wp-db.php on line 1454

如果在 debug.log 或 php_errors.log 文件中看到此错误,则表示应用连接数已超出可用数目。If you see this error in your debug.log or php_errors.log files, your app is exceeding the number of connections. 如果在 ClearDB 上承载,请验证服务计划中可用的连接数。If you’re hosting on ClearDB, verify the number of connections that are available in your service plan.

如何调试应用服务中承载的 Node.js 应用?How do I debug a Node.js app that's hosted in App Service?

  1. 转到 Kudu 控制台 (https://*yourwebsitename*.scm.chinacloudsites.cn/DebugConsole)。Go to your Kudu console (https://*yourwebsitename*.scm.chinacloudsites.cn/DebugConsole).
  2. 转到应用程序日志文件夹 (D:\home\LogFiles\Application)。Go to your application logs folder (D:\home\LogFiles\Application).
  3. 在 logging_errors.txt 文件中,检查内容。In the logging_errors.txt file, check for content.

如何在应用服务 Web 应用或 API 应用中安装本机 Python 模块?How do I install native Python modules in an App Service web app or API app?

某些包可能并不通过使用 pip 在 Azure 中安装。Some packages might not install by using pip in Azure. 该包可能在 Python 包索引上不可用,或可能需要编译器(编译器在运行应用服务中 Web 应用的计算机上不可用)。The package might not be available on the Python Package Index, or a compiler might be required (a compiler is not available on the computer that is running the web app in App Service). 有关在应用服务 Web 应用和 API 应用中安装本机模块的信息,请参阅在应用服务中安装 Python 模块For information about installing native modules in App Service web apps and API apps, see Install Python modules in App Service.

如何通过使用 Git 和新版 Python 将 Django 应用部署到应用服务?How do I deploy a Django app to App Service by using Git and the new version of Python?

有关安装 Django 的信息,请参阅将 Django 应用部署到应用服务For information about installing Django, see Deploying a Django app to App Service.

Tomcat 日志文件位于何处?Where are the Tomcat log files located?

对于 Azure 市场和自定义部署:For Azure Marketplace and custom deployments:

  • 文件夹位置:D:\home\site\wwwroot\bin\apache-tomcat-8.0.33\logsFolder location: D:\home\site\wwwroot\bin\apache-tomcat-8.0.33\logs
  • 感兴趣的文件:Files of interest:
    • catalina.yyyy-mm-dd.logcatalina.yyyy-mm-dd.log
    • host-manager.yyyy-mm-dd.loghost-manager.yyyy-mm-dd.log
    • localhost.yyyy-mm-dd.loglocalhost.yyyy-mm-dd.log
    • manager.yyyy-mm-dd.logmanager.yyyy-mm-dd.log
    • site_access_log.yyyy-mm-dd.logsite_access_log.yyyy-mm-dd.log

对于门户“应用设置”部署:For portal App settings deployments:

  • 文件夹位置:D:\home\LogFilesFolder location: D:\home\LogFiles
  • 感兴趣的文件:Files of interest:
    • catalina.yyyy-mm-dd.logcatalina.yyyy-mm-dd.log
    • host-manager.yyyy-mm-dd.loghost-manager.yyyy-mm-dd.log
    • localhost.yyyy-mm-dd.loglocalhost.yyyy-mm-dd.log
    • manager.yyyy-mm-dd.logmanager.yyyy-mm-dd.log
    • site_access_log.yyyy-mm-dd.logsite_access_log.yyyy-mm-dd.log

如何解决 JDBC 驱动程序连接错误的问题?How do I troubleshoot JDBC driver connection errors?

可能会在 Tomcat 日志中看到以下消息:You might see the following message in your Tomcat logs:

The web application[ROOT] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak,the JDBC Driver has been forcibly unregistered

若要解决该错误:To resolve the error:

  1. 从 app/lib 文件夹中删除 sqljdbc*.jar 文件。Remove the sqljdbc*.jar file from your app/lib folder.

  2. 如果使用自定义 Tomcat 或 Azure 市场 Tomcat Web 服务器,请将此 .jar 文件复制到 Tomcat lib 文件夹中。If you are using the custom Tomcat or Azure Marketplace Tomcat web server, copy this .jar file to the Tomcat lib folder.

  3. 如果从 Azure 门户启用 Java(选择“Java 1.8” > “Tomcat 服务器”),请在并行于应用的文件夹中复制 sqljdbc.* jar 文件。If you are enabling Java from the Azure portal (select Java 1.8 > Tomcat server), copy the sqljdbc.* jar file in the folder that's parallel to your app. 然后,将以下 classpath 设置添加到 web.config 文件中:Then, add the following classpath setting to the web.config file:

    <httpPlatform>
    <environmentVariables>
    <environmentVariablename ="JAVA_OPTS" value=" -Djava.net.preferIPv4Stack=true
    -Xms128M -classpath %CLASSPATH%;[Path to the sqljdbc*.jarfile]" />
    </environmentVariables>
    </httpPlatform>
    

为什么当我尝试复制实时日志文件时看到错误?Why do I see errors when I attempt to copy live log files?

如果尝试复制 Java 应用(例如 Tomcat)的实时日志文件,可能会看到此 FTP 错误:If you try to copy live log files for a Java app (for example, Tomcat), you might see this FTP error:

Error transferring file [filename] Copying files from remote side failed.
    
The process cannot access the file because it is being used by another process.

错误消息可能会有所不同,具体取决于 FTP 客户端。The error message might vary, depending on the FTP client.

所有 Java 应用都具有此锁定问题。All Java apps have this locking issue. 仅 Kudu 支持在应用运行时下载此文件。Only Kudu supports downloading this file while the app is running.

停止应用可允许对这些文件的 FTP 访问。Stopping the app allows FTP access to these files.

另一解决方法是编写按计划运行并将这些文件复制到另一个目录的 WebJob。Another workaround is to write a WebJob that runs on a schedule and copies these files to a different directory. 对于示例项目,请参阅 CopyLogsJob 项目。For a sample project, see the CopyLogsJob project.

在哪里可以找到 Jetty 的日志文件?Where do I find the log files for Jetty?

对于市场和自定义部署,日志文件位于 D:\home\site\wwwroot\bin\jetty-distribution-9.1.2.v20140210\logs 文件夹中。For Marketplace and custom deployments, the log file is in the D:\home\site\wwwroot\bin\jetty-distribution-9.1.2.v20140210\logs folder. 请注意,文件夹位置取决于所使用的 Jetty 版本。Note that the folder location depends on the version of Jetty you are using. 例如,以下提供的路径用于 Jetty 9.1.2。For example, the path provided here is for Jetty 9.1.2. 查找 jetty_ YYYY_MM_DD.stderrout.log。Look for jetty_ YYYY_MM_DD.stderrout.log.

对于门户应用设置部署,日志文件位于 D:\home\LogFiles。For portal App Setting deployments, the log file is in D:\home\LogFiles. 查找 jetty_ YYYY_MM_DD.stderrout.logLook for jetty_ YYYY_MM_DD.stderrout.log

是否可从 Azure web 应用发送电子邮件?Can I send email from my Azure web app?

应用服务没有内置电子邮件功能。App Service doesn't have a built-in email feature. 有关从应用发送电子邮件的一些不错的替代方案,请参阅此 Stack Overflow 讨论For some good alternatives for sending email from your app, see this Stack Overflow discussion.

为什么我的 WordPress 站点会重定向到另一个 URL?Why does my WordPress site redirect to another URL?

如果已在最近迁移到 Azure,WordPress 可能会重定向到旧的域 URL。If you have recently migrated to Azure, WordPress might redirect to the old domain URL. 这是由 MySQL 数据库中的设置所致。This is caused by a setting in the MySQL database.

若要使用 SQL 查询或 PHPMyAdmin 手动更新重定向 URL,请参阅 WordPress:重定向到错误 URLTo manually update the redirection URL by using SQL queries or PHPMyAdmin, see WordPress: Redirecting to wrong URL.

如何迁移我的 WordPress 数据库?How do I migrate my WordPress database?

有多种方法可用于迁移连接到 WordPress 网站的 MySQL 数据库:You have multiple options for migrating the MySQL database that's connected to your WordPress website:

使用命令提示符或 PHPMyAdminUse the command prompt or PHPMyAdmin

我如何提供帮助,可让 WordPress 更加安全?How do I help make WordPress more secure?

若要了解有关 WordPress 的安全性最佳做法,请参阅 Azure 中的 WordPress 安全性最佳做法To learn about security best practices for WordPress, see Best practices for WordPress security in Azure.

我在尝试使用 PHPMyAdmin,但看到消息“拒绝访问”。I am trying to use PHPMyAdmin, and I see the message “Access denied.” 如何解决此问题?How do I resolve this?

如果 MySQL 应用内功能尚未在此应用服务实例中运行,可能会遇到此问题。You might experience this issue if the MySQL in-app feature isn't running yet in this App Service instance. 若要解决此问题,请尝试访问自己的网站。To resolve the issue, try to access your website. 这将启动所需的进程,包括 MySQL 应用内进程。This starts the required processes, including the MySQL in-app process. 若要验证 MySQL 应用内功能正在运行,确保进程资源管理器 的进程中列出了 mysqld.exe。To verify that MySQL in-app is running, in Process Explorer, ensure that mysqld.exe is listed in the processes.

确保 MySQL 应用内功能运行后,尝试使用 PHPMyAdmin。After you ensure that MySQL in-app is running, try to use PHPMyAdmin.

在尝试使用 PHPMyadmin 导入或导出 MySQL 应用内数据库时,收到了 HTTP 403 错误。I get an HTTP 403 error when I try to import or export my MySQL in-app database by using PHPMyadmin. 如何解决此问题?How do I resolve this?

如果使用的是较旧版本的 Chrome,则可能遇到一个已知的 bug。If you are using an older version of Chrome, you might be experiencing a known bug. 要解决此问题,请升级到较新版本的 Chrome。To resolve the issue, upgrade to a newer version of Chrome. 另请尝试使用不会出现该问题的不同浏览器,如 Internet Explorer 或 Microsoft Edge。Also try using a different browser, like Internet Explorer or Microsoft Edge, where the issue does not occur.