apache配置中的权限被拒绝:[Errno 13]权限被拒绝

时间:2018-01-02 06:10:21

标签: python linux flask ubuntu-16.04 apache2.4

使用wsgi在apache2.4(ubuntu 16)上主持烧瓶,但在浏览器中我遇到500错误:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@51.255.213.181 to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.25 (Ubuntu) Server at 51.255.213.181 Port 80

当我运行tail -f /var/log/apache2/error.log时:

[Tue Jan 02 05:27:28.444613 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868] Traceback (most recent call last):
[Tue Jan 02 05:27:28.444688 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]   File "/var/www/TW96/tw96.wsgi", line 4, in 
[Tue Jan 02 05:27:28.444703 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]     from index import app as application
[Tue Jan 02 05:27:28.444717 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]   File "/var/www/TW96/tw96/index.py", line 32, in 
[Tue Jan 02 05:27:28.444740 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]     app.run(port=80,debug=True)
[Tue Jan 02 05:27:28.444755 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 841, in run
[Tue Jan 02 05:27:28.444766 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]     run_simple(host, port, self, **options)
[Tue Jan 02 05:27:28.444789 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]   File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 780, in run_simple
[Tue Jan 02 05:27:28.444799 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868]     s.bind((hostname, port))
[Tue Jan 02 05:27:28.444825 2018] [wsgi:error] [pid 3308:tid 139686857123584] [client 209.95.51.167:53868] PermissionError: [Errno 13] Permission denied

这是我的apache配置文件:

<VirtualHost *:80>
                ServerName roboticworkshop.ir
                ServerAdmin root@51.255.213.181
                WSGIScriptAlias / /var/www/TW96/tw96.wsgi
                <Directory /var/www/TW96/tw96/>
                        Require all granted
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

这是我的wsgi文件:

import sys,os
sys.path.insert(0,"/var/www/TW96/tw96")
os.chdir("/var/www/TW96/tw96")
from index import app as application

和www文件夹:

TW96
....tw96
........index.py
........static
........templates
....tw96.wsgi

1 个答案:

答案 0 :(得分:0)

/var/www/TW96/tw96/index.py的第32行在端口80上启动HTTP服务器:

app.run(port=80,debug=True)

这失败是因为first 1024 ports are for privileged users only。即使您的应用程序以特权用户身份运行,Apache也在监听该端口,因此您无法打开它。

在任何情况下,导入应用程序都不应该首先启动HTTP服务器。删除第32行。

相关问题