【发布时间】:2018-09-14 17:57:30
【问题描述】:
我正在编写一个非常简单的 Flask 程序来记录 POST 有效负载。它在调试中运行良好,所以我将它连接到 apache。现在我得到 “IOError:[Errno 13] 权限被拒绝:”尝试在除 /tmp 之外的任何位置登录时。
我在 RHEL 7.x 上运行 apache v2.4.6 和 wsgi v3.4。 这是我的东西:
虚拟主机文件:
Listen *:8080
<VirtualHost *:8080>
ServerName www.test.com
ErrorLog /var/log/httpd/error2.log
CustomLog /var/log/httpd/access2.log combined
# didn't work
#<Directory />
# Options Indexes FollowSymLinks Includes ExecCGI
# AllowOverride All
# Require all granted
#</Directory>
WSGIDaemonProcess csplogger user=apache group=apache threads=5
WSGIProcessGroup csplogger
WSGIScriptAlias /report-to /var/www/FLASKAPPS/csplogger/csplogger.wsgi
</VirtualHost>
csplogger.wsgi 文件:
#!/bin/python
import sys
sys.path.insert(0,"/var/www/FLASKAPPS/")
from csplogger import app as application
还有蟒蛇:
from flask import Flask, request
import json
import os
import logging
from logging import Formatter, FileHandler
from logging.handlers import RotatingFileHandler
app = Flask(__name__)
if not app.debug:
logdir = '/opt/logs/'
file_handler = FileHandler('/tmp/access.log')
#file_handler = FileHandler(logdir + 'access.log')
#file_handler = RotatingFileHandler(logdir + 'access.log', maxBytes=20000000, backupCount=10)
file_handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s'))
logging.getLogger('werkzeug').setLevel(logging.INFO)
logging.getLogger('werkzeug').addHandler(file_handler)
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
# adding some debug
app.logger.info(os.environ)
app.logger.info(os.path.dirname(logdir).format())
app.logger.info(os.listdir(logdir))
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method != 'POST':
app.logger.info('GET testing'.format())
return ('not a post\n', 200)
else:
data = request.get_json()
app.logger.info(json.dumps(data))
return ('', 204)
if __name__ =='__main__':
app.run(host='0.0.0.0', port=5000, debug=False)
/opt/logs 是预期的日志目标。它是 chown'd apache:apache (这是我的 apache 用户/组)并且 perm'd 完全开放。我知道 python 应用程序可以找到这些目录,因为我列出了内容并将其记录(当记录到 /tmp/access.log 时)作为调试的一部分。我提到这是 RHEL,但我没有提到 SELinux 被禁用。
长话短说,我可以看到一个目录中的文件,这两个文件都是 777 并归 apache 用户所有,但我不能写那些日志文件。
感谢您的宝贵时间。任何帮助将不胜感激。
【问题讨论】:
-
这是个坏问题吗?是不是太简单了以至于不值得回答?还是没有其他人看到它?
-
有机会解决吗?
标签: python apache logging flask mod-wsgi