【问题标题】:disable cache on apache with python bottle wsgi使用 python bottle wsgi 禁用 apache 上的缓存
【发布时间】:2018-10-05 14:24:00
【问题描述】:

在 Apache 上使用 Python Bottle 开发时遇到问题。每次我更改导入到主 app.wsgi 的文件 dbmanager.py 时,都没有任何变化。我需要“触摸”app.wsgi 以查看 dbmanager.py 中的更改或重新启动 apache。我尝试了一切:.htaccess 中的更改,apache 虚拟主机配置。但仍然没有。有什么想法吗?

我的文件的路径是:

/var/www/paka/public_html/edi/api/app.wsgi

我有两个文件:

app.wsgi

import os, sys
from os.path import dirname
sys.path.append(dirname(__file__))

import bottle
from bottle import route, run, template, post, request, response
bottle.debug(True)
bottle.TEMPLATES.clear()

import dbmanager
c = dbmanager.connect()

@route('/hello/<name>')
def index(name):
    #return hello.world()  # only log in console
    return template('<b>Hello  {{name}}</b>!' + c, name=name)

application = bottle.default_app()

和 dbmanager.py

import mysql, mysql.connector

def connect():
    return "123456"

我的 .htaccess

# DISABLE CACHING
ExpiresActive On
ExpiresDefault A1
Header append Cache-Control must-revalidate

<IfModule mod_headers.c>
        Header set Cache-Control "no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires 0
</IfModule>

<FilesMatch "\.(css|flv|gif|htm|html|ico|jpe|jpeg|jpg|js|png|pdf|swf|txt|py|pcc)$">
        <IfModule mod_expires.c>
                ExpiresActive Off
        </IfModule>
        <IfModule mod_headers.c>
                FileETag None
                Header unset ETag
                Header unset Pragma
                Header unset Cache-Control
                Header unset Last-Modified
                Header set Pragma "no-cache"
                Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
                Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
        </IfModule>
</FilesMatch>

我的虚拟主机配置:

WSGIDaemonProcess bottle user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /var/www/paka/public_html/edi/api/app.wsgi

<Directory /var/www/paka/public_html/edi/api/>
    WSGIProcessGroup bottle
    WSGIApplicationGroup %{GLOBAL}
    Require all granted
</Directory>

【问题讨论】:

  • 文件更改后尝试重启apache?
  • 是的,当我重新启动 apache 时,我看到了变化。那么就没有其他选择了吗?修改文件后总是需要重启jeeves?

标签: python apache mod-wsgi wsgi bottle


【解决方案1】:

源代码重新加载的主题在 mod_wsgi 文档中有详细介绍。

您必须接触 WSGI 脚本文件,或者如果这是一个开发系统,您可以按照文档中的说明将一些代码添加到 WSGI 脚本中,这将检测更改并自动重启进程。

更好的是,对于开发,使用mod_wsgi-express 并使用--reload-on-changes 选项。

有关此主题的文档中的详细信息太多,无法在此处批发剪切和粘贴。

【讨论】:

    猜你喜欢
    • 2016-12-19
    • 2013-08-12
    • 2012-09-22
    • 1970-01-01
    • 2011-12-19
    • 2011-11-24
    • 2014-05-18
    • 1970-01-01
    • 2013-01-02
    相关资源
    最近更新 更多