在 web 服务器(flask、apache 和 wsgi)上写入文件时的权限问题
Permission issue when writing file on webserver (flask, apache & wsgi)
我正在尝试部署我的第一个网络应用程序,但我对此一无所知。这很有趣,但是当我尝试解决问题时,我觉得自己不知道自己在做什么。
我在 ubuntu 18.04 运行 上创建了一个服务器,为了让我的网站 运行 顺利运行,我在过去的 2 天里一直在努力.
我现在觉得快结束了,但我卡在权限访问问题上。
我的应用程序通过 Flask 运行。我正在使用 wsgi_mod 和 apache 来 运行 它。
我已经放下了 2 个可以帮助你的安装文件(我想?)以及错误日志。
我还尝试应用以下修复:
sudo chown -R www-data:www-data /var/www/website.com
sudo cmod -R 775 /var/www/website.com
我尝试 运行 使用 WSGIDaemon 进程的 wsgi(无论它用于什么都不起作用)。
请帮帮我!
如果您需要更多问题,请告诉我。
非常感谢!
错误日志:
Traceback (most recent call last):
File "/var/www/website.com/wsgi/website.com.wsgi", line 10, in <module>
from __init__ import app as application
File "/var/www/website.com/akb/__init__.py", line 19, in <module>
flask_session.Session(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 5$
self.init_app(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 6$
app.session_interface = self._get_interface(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 9$
config['SESSION_USE_SIGNER'], config['SESSION_PERMANENT'])
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/sessions.py", line 3$
self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/werkzeug/contrib/cache.py", line 7$
os.makedirs(self._path)
File "/usr/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/flask_session'
/var/www/website/wsgi/website.com.wsgi
#!/var/www/website.com/akb/env3.7/bin/python
# -*- coding: utf-8 -*-
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/website.com/akb")
from __init__ import app as application
application.secret_key = 'iuhAqshdad123_&é"_JIHfduh3i123d!!:'
/etc/apache2/sites-available/website.com.conf:
WSGIPythonHome /var/www/website.com/akb/env3.7
<VirtualHost *:80>
ServerName website.com
ServerAdmin website.root@gmail.com
ServerAlias www.website.com
DocumentRoot /var/www/website.com/akb
<Directory /var/www/website.com/akb>
<IfVersion < 2.4>
Order allow,deny,
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/website.com/wsgi/website.com.wsgi
<Directory /var/www/website.com/akb>
WSGIProcessGroup website.com
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
Alias /static /var/www/website.com/akb/static
<Directory /var/www/website.com/akb/static>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
Alias /templates /var/www/website.com/akb/templates
<Directory /var/www/website.com/akb/templates>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
ErrorLog /var/www/website.com/errors/error.log
LogLevel info
CustomLog /var/www/website.com/errors/access.log combined
我终于解决了这个问题:
- 通过将 os 目录更改为我的环境之一 (os.chdir)
- 使用 chown/chmod 授予 edit/create 对 www-data
的权利
我正在尝试部署我的第一个网络应用程序,但我对此一无所知。这很有趣,但是当我尝试解决问题时,我觉得自己不知道自己在做什么。
我在 ubuntu 18.04 运行 上创建了一个服务器,为了让我的网站 运行 顺利运行,我在过去的 2 天里一直在努力.
我现在觉得快结束了,但我卡在权限访问问题上。
我的应用程序通过 Flask 运行。我正在使用 wsgi_mod 和 apache 来 运行 它。
我已经放下了 2 个可以帮助你的安装文件(我想?)以及错误日志。
我还尝试应用以下修复:
sudo chown -R www-data:www-data /var/www/website.com
sudo cmod -R 775 /var/www/website.com
我尝试 运行 使用 WSGIDaemon 进程的 wsgi(无论它用于什么都不起作用)。
请帮帮我!
如果您需要更多问题,请告诉我。
非常感谢!
错误日志:
Traceback (most recent call last):
File "/var/www/website.com/wsgi/website.com.wsgi", line 10, in <module>
from __init__ import app as application
File "/var/www/website.com/akb/__init__.py", line 19, in <module>
flask_session.Session(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 5$
self.init_app(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 6$
app.session_interface = self._get_interface(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 9$
config['SESSION_USE_SIGNER'], config['SESSION_PERMANENT'])
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/sessions.py", line 3$
self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/werkzeug/contrib/cache.py", line 7$
os.makedirs(self._path)
File "/usr/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/flask_session'
/var/www/website/wsgi/website.com.wsgi
#!/var/www/website.com/akb/env3.7/bin/python
# -*- coding: utf-8 -*-
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/website.com/akb")
from __init__ import app as application
application.secret_key = 'iuhAqshdad123_&é"_JIHfduh3i123d!!:'
/etc/apache2/sites-available/website.com.conf:
WSGIPythonHome /var/www/website.com/akb/env3.7
<VirtualHost *:80>
ServerName website.com
ServerAdmin website.root@gmail.com
ServerAlias www.website.com
DocumentRoot /var/www/website.com/akb
<Directory /var/www/website.com/akb>
<IfVersion < 2.4>
Order allow,deny,
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/website.com/wsgi/website.com.wsgi
<Directory /var/www/website.com/akb>
WSGIProcessGroup website.com
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
Alias /static /var/www/website.com/akb/static
<Directory /var/www/website.com/akb/static>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
Alias /templates /var/www/website.com/akb/templates
<Directory /var/www/website.com/akb/templates>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
ErrorLog /var/www/website.com/errors/error.log
LogLevel info
CustomLog /var/www/website.com/errors/access.log combined
我终于解决了这个问题:
- 通过将 os 目录更改为我的环境之一 (os.chdir)
- 使用 chown/chmod 授予 edit/create 对 www-data 的权利