在网络服务器上写入文件时的权限问题(烧瓶,apache和wsgi) [英] Permission issue when writing file on webserver (flask, apache & wsgi)

查看:65
本文介绍了在网络服务器上写入文件时的权限问题(烧瓶,apache和wsgi)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署我的第一个Web应用程序,对此我一无所知.相当有趣,但是当我尝试解决问题时,我感觉不知道自己在做什么.

I'm trying to deploy my very first web app and I have no knowledge on this. It's fairly interesting but I feel like I have no idea what I am doing when I try to fix an issue.

我在数字海洋上创建了一个服务器,该服务器运行在ubuntu 18.04上,并且在过去的两天里一直在与之作战,目的是使我的网站平稳运行.

I created a server on digital ocean which run on ubuntu 18.04 and I've been fighting with it over the past 2 days in order to make my website run smoothly.

我现在感觉到尽头了,但是我遇到了权限访问问题.

I now feel that the end is near but I am stuck on a permission access issue.

我的应用正在通过烧瓶工作.我正在使用wsgi_mod和apache来运行它.

My app is working through flask. I'm using wsgi_mod and apache to run it.

我放下了两个可以帮助您(我认为是)的安装文件以及错误日志.

I've put down 2 of the setup file that can help you (I think ?) as well as the error log.

我还尝试应用以下修复程序:

I have also tried to apply the following fix:

sudo chown -R www-data:www-data/var/www/website.com

sudo chown -R www-data:www-data /var/www/website.com

sudo cmod -R 775/var/www/website.com

sudo cmod -R 775 /var/www/website.com

我尝试使用WSGIDaemon进程运行wsgi(无论用于什么都行不通).

I tried to run the wsgi using the WSGIDaemon process (whatever it is used for it didn't work neither).

请帮助我!

让我知道是否需要更多问题.

Let me know if you need more question.

非常感谢!

错误日志:

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/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:

/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授予www-data的编辑/创建权限

这篇关于在网络服务器上写入文件时的权限问题(烧瓶,apache和wsgi)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆