MoinMoin部署:Nginx+uwsgi

1 篇文章 0 订阅

本文假设nginx,uwsgi都已经安装完毕!


1. 首先安装flup,不多说,easy_install flup

2. 下载moinmoin,我用的是1.9.5,解压到/data下,并做符号链接ln moin-1.9.5 moin -s

3. cd /data/moin/wiki;

4. cp server/moin.wsgi .

5. cp config/wikiconfig.py .

6. 修改moin.wsgi, 找到a2,加入:

sys.path.insert(0, '/data/moin/wiki')

7. 启动uwsgi:

uwsgi -s 127.0.0.1:9003 -M -t 30 -A 4 -p 2 -d /var/log/moin-uwsgi.log --pythonpath /data/moin --wsgi-file /data/moin/wiki/moin.wsgi

8. 修改nginx配置,加入一下虚拟主机设置:

server {
  listen          8080;
  # Replace this with your domain name
  server_name     wiki.xxxx.com;

  location / {
    include uwsgi_params;
    uwsgi_pass 127.0.0.1:9003;
  }
}

9. 重新启动nginx,加载新的配置;


10. DONE !如果没有任何问题提示,现在可以访问ip:8080来打开wiki页面了!



Update: MoinMoin官方wiki上说明的External Cookie(http://moinmo.in/HelpOnAuthentication/ExternalCookie)验证方式verifySessionPlus有一个潜在的BUG:

def verifySessionPlus(sidHash,timeout=3600*4): # +++ to use this, uncomment a procedure call below in ExternalCookie
    """Return True if sidHash value exists (meaning user is currently logged on), false otherwise.  
    
    This version of verifySession deletes entries inactive for more than 4 hours and
    updates the tStamp field with each moin transaction.  If performance is 
    important, find another way to delete inactive sessions.
    """
    db = MySQLdb.connect(db='mydb',user='myuserid',passwd='mypw') # +++ user ID needs write access
    c = db.cursor()
    q = 'delete from ActiveSession where tStamp<"%s"' % int(time.time() - timeout) # delete inactive entries
    result = c.execute(q)
    q = 'update ActiveSession set tStamp=%s where sidHash="%s"' % (int(time.time()),sidHash)
    result = c.execute(q)
    c.close()
    if result == 1:
        return True
    return False
    

其中,为了判断某用户是否具有一个合法的session的时候,使用的是一个update语句的返回值,在实际使用中发现,如果快速刷新页面,会在用户拥有合法session的前提下也会判断为无效用户。具体的修正方法是,在判断之前做一次select操作,用select的操作替代update操作:


def verifySessionPlus(sidHash,timeout=3600*4): # +++ to use this, uncomment a procedure call below in ExternalCookie
    """Return True if sidHash value exists (meaning user is currently logged on), false otherwise.  
    
    This version of verifySession deletes entries inactive for more than 4 hours and
    updates the tStamp field with each moin transaction.  If performance is 
    important, find another way to delete inactive sessions.
    """
    db = MySQLdb.connect(db=DATABASE['NAME'],user=DATABASE['USER'],passwd=DATABASE['PASSWORD']) # +++ user ID needs write access
    c = db.cursor()
    q = 'delete from ActiveSession where tStamp<"%s"' % int(time.time() - timeout) # delete inactive entries
    result = c.execute(q)
    q = 'update ActiveSession set tStamp=%s where sidHash="%s"' % (int(time.time()),sidHash)
    result = c.execute(q)
    q = 'select * from ActiveSession where sidHash="%s"' % sidHash
    result = c.execute(q)
    c.close()
    if result >= 1:
        return True
    return False


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值