将 mod-wsgi 用于 运行 使用 python3 编写的应用程序时出现问题

Problem getting mod-wsgi to run an app written using python3

几周来我一直在研究这个问题。我 mod_wsgi 使用这些 instructions and and this YouTube video

当我使用我所学的知识在我的网络服务器上运行我自己的应用程序时,我遇到了一些问题,但解决了大部分问题。 “障碍”是我为 Python 3.6 编写了我的应用程序并且导入导致错误,因为 mod_wsgi 试图用 Python 2.7 运行 它们。进一步的研究让我意识到我需要安装 libapache2-mod-wsgi-py3 而不是 libapache2-mod-wsgi。至少,这就是我从阅读中想到的 here

现在,我有一个新的错误:

ubuntu@ip-172-26-13-175:~$ sudo systemctl start apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

基于此,我尝试:

ubuntu@ip-172-26-13-175:~$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Tue 2020-06-30 18:44:53 UTC; 14s ago
  Process: 6773 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

Jun 30 18:44:53 ip-172-26-13-175 systemd[1]: Starting The Apache HTTP Server...
Jun 30 18:44:53 ip-172-26-13-175 apachectl[6773]: AH00526: Syntax error on line 1 of /etc/apache2/conf-enabled/mod-wsgi.conf:
Jun 30 18:44:53 ip-172-26-13-175 apachectl[6773]: Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration
Jun 30 18:44:53 ip-172-26-13-175 apachectl[6773]: Action 'start' failed.
Jun 30 18:44:53 ip-172-26-13-175 apachectl[6773]: The Apache error log may have more information.
Jun 30 18:44:53 ip-172-26-13-175 systemd[1]: apache2.service: Control process exited, code=exited status=1
Jun 30 18:44:53 ip-172-26-13-175 systemd[1]: apache2.service: Failed with result 'exit-code'.
Jun 30 18:44:53 ip-172-26-13-175 systemd[1]: Failed to start The Apache HTTP Server.

基于此我检查:

ubuntu@ip-172-26-13-175:~$ cat /etc/apache2/conf-enabled/mod-wsgi.conf
WSGIScriptAlias /test_wsgi /var/www/html/wsgi_test_script.py

并基于此,我检查该别名的目标是否存在以及是否具有有效代码:

ubuntu@ip-172-26-13-175:~$ cat /var/www/html/wsgi_test_script.py
def application(environ,start_response):
    status = '200 OK'
    html = '<html>\n' \
           '<body>\n' \
           ' Hooray, mod_wsgi is working\n' \
           '</body>\n' \
           '</html>\n'
    response_header = [('Content-type','text/html')]
    start_response(status,response_header)
    return [html]

既然都检查过了,我不知道如何解决这个问题。我什至不知道接下来要检查什么。显然,如果我无法启动 Apache,我的 Flask/mod_wsgi 应用程序将无法运行。

如有任何帮助,我们将不胜感激!

我想通了。

我只是禁用了导致问题的 conf:

sudo a2disconf mod-wsgi.conf

Apache 现在完美启动。