简体   繁体   English

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

[英]permission denied in apache configuration : [Errno 13] Permission denied

Im tring to host flask on apache2.4(ubuntu 16) using wsgi and but im facing 500 error in browser:我想使用wsgi在apache2.4(ubuntu 16)上托管flask,但我在浏览器中遇到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

when i run tail -f /var/log/apache2/error.log :当我运行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

this is my apache configuration file:这是我的 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>

and this is my wsgi file:这是我的 wsgi 文件:

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

and the www folder:和 www 文件夹:

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

Line 32 of /var/www/TW96/tw96/index.py starts an HTTP server on port 80: /var/www/TW96/tw96/index.py第32 /var/www/TW96/tw96/index.py端口80上启动HTTP服务器:

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

This fails because the first 1024 ports are for privileged users only . 这将失败,因为前1024个端口仅适用于特权用户 Even if your application would run as a privileged user, Apache is already listening on that port, so you can't open it. 即使您的应用程序将以特权用户身份运行,Apache也已经在该端口上进行监听,因此您无法打开它。

In any case, importing your application should not start an HTTP server in the first place. 无论如何,导入应用程序都不应首先启动HTTP服务器。 Remove line 32. 删除第32行。

Just run below command it was worked for me只需在命令下运行它对我有用

$ sudo chown -R www-data:www-data /var/www/TW96/tw96/

Checking file ownership检查文件所有权

If you have created any new files & folders in your website's folder then its owner may be the Linux user you are currently logged in as.如果您在网站文件夹中创建了任何新文件和文件夹,则其所有者可能是您当前登录的 Linux 用户。 For example, if you are currently logged in as user ubuntu and create a new file in /var/www/html then its owner will be ubuntu.例如,如果您当前以用户 ubuntu 登录并在 /var/www/html 中创建一个新文件,则其所有者将为 ubuntu。 By default Apache uses www-data user to access your website's files & folders by default.默认情况下,Apache 默认使用 www-data 用户访问您网站的文件和文件夹。

So in this case, you will need to change the user of newly created files & folders.因此,在这种情况下,您需要更改新创建文件和文件夹的用户。 Run the following command to set the owner of your website files & folders recursively.运行以下命令以递归方式设置网站文件和文件夹的所有者。

$ sudo chown -R www-data:www-data /var/www/html

for more detailed references please check this below link有关更详细的参考资料,请查看以下链接

https://fedingo.com/how-to-fix-errno-13-permission-denied-error-in-apache/ https://fedingo.com/how-to-fix-errno-13-permission-denied-error-in-apache/

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

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