我已经花了几个星期来研究这个问题了。我使用这些instructions和this YouTube video让mod_wsgi工作。
当我使用我所学到的知识将我自己的应用程序放在我的web服务器上时,我遇到了一些问题,但我解决了大部分问题。“拦路虎”是我为Python3.6编写的应用程序,导入导致了错误,因为mod_wsgi试图使用Python2.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应用程序将无法工作。
任何帮助都将不胜感激!
发布于 2020-07-01 21:11:52
我想通了。
我只是使用以下命令禁用了导致问题的conf:
sudo a2disconf mod-wsgi.conf
Apache现在完美地启动了。
https://stackoverflow.com/questions/62666052
复制