利用Python脚本在Nginx和uwsgi上部署MoinMoin的教程


Posted in Python onMay 05, 2015

在 CentOS 下使用 apache+mod_wsgi 部署了 MoinMoin,但是编辑和保存页面很慢,于是准备使用 nginx+uwsgi 重新部署

本文假定已经按照官方指引 Quick MoinMoin on CentOS 完成了 apache 和 mod_wsgi 之外的基础安装
安装 Nginx

默认情况下,CentOS 下没有 nginx 的源,需要自己手动添加,访问 http://nginx.org/en/linux_packages.html#stable 下载 CentOS 6 的 rpm 包,并安装

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

然后执行下面的命令安装 nginx

yum install nginx

安装 uwsgi

安装 python 包管理工具 pip

yum install python-devel python-setuptools
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py -O - | python

通过 pip 安装 uwsgi (使用豆瓣的境像)

pip install -v uwsgi -i http://pypi.douban.com/simple

使用 uwsgi 启动 moin

创建 uwsgi 配置 /etc/uwsgi/uwsgi.xml 内容如下

<uwsgi>
<socket>/var/run/moin.sock</socket>                                           
<chmod-socket>666</chmod-socket>
<limit-as>256</limit-as>
<processes>6</processes>
<memory-report/>
<vhost/>
<no-site/>
</uwsgi>

其中 <chmod-socket>666</chmod-socket> 这句是这了防止 nginx 访问 moin.sock 没有权限。

重命名 moin 的 wsgi 启动脚本,以被 uwsgi 识别

cd /usr/local/share/moin
mv moin.wsgi moin_wsgi.py

要启动 uwsgi 可以使用下面的命令

uwsgi -x /etc/uwsgi/uwsgi.xml

配置 nginx 访问 uwsgi

建立 /etc/nginx/conf.d/moin.conf 内容如下

# moinmoin 虚拟主机配置
server {
  listen YOUR_SERVER_IP:80;
  server_name localhost;

  access_log /var/log/nginx/moin.access_log main;
  error_log /var/log/nginx/moin.error_log info;

  location ^~ / {
    include uwsgi_params;
    uwsgi_pass unix:///var/run/moin.sock;
    # uwsgi_param UWSGI_PYHOME /usr/local/lib/python2.6/; #site-packages/;
    uwsgi_param UWSGI_CHDIR /usr/local/share/moin/;
    uwsgi_param UWSGI_SCRIPT moin_wsgi;
    uwsgi_param SCRIPT_NAME /;
    uwsgi_modifier1 30;
  }

  location ^~ /moin_static193/ {
    alias /usr/local/lib/python2.6/site-packages/MoinMoin/web/static/htdocs/;
    add_header Cache-Control public;
    expires 1M;
  }
}

运行 nginx

nginx

运行及故障排除

接下来你可以通过浏览器访问 Wiki 了,但是发现编辑和保存页面依旧很慢,然后稍微 Google 了下就发现了 一篇解决这个问题的文章,很快解决了慢的问题

编辑 wikiconfig.py 加入如下配置

log_reverse_dns_lookups = False

重启 uwsgi 后再访问 Wiki,发现慢的问题解决了(为什么我之前没有找到这篇文章!)

Python 相关文章推荐
在RedHat系Linux上部署Python的Celery框架的教程
Apr 07 Python
python正常时间和unix时间戳相互转换的方法
Apr 23 Python
Python使用metaclass实现Singleton模式的方法
May 05 Python
Python多线程爬虫简单示例
Mar 04 Python
Python常见数据结构之栈与队列用法示例
Jan 14 Python
使用python实现数组、链表、队列、栈的方法
Dec 20 Python
Python3.7.0 Shell添加清屏快捷键的实现示例
Mar 23 Python
django在开发中取消外键约束的实现
May 20 Python
Django crontab定时任务模块操作方法解析
Sep 10 Python
利用python如何实现猫捉老鼠小游戏
Dec 04 Python
Python的信号库Blinker用法详解
Dec 31 Python
在python中读取和写入CSV文件详情
Jun 28 Python
Python实现的HTTP并发测试完整示例
Apr 23 #Python
安装dbus-python的简要教程
May 05 #Python
使用SAE部署Python运行环境的教程
May 05 #Python
在Python中使用PIL模块对图片进行高斯模糊处理的教程
May 05 #Python
在Python中使用mechanize模块模拟浏览器功能
May 05 #Python
python实现自动更换ip的方法
May 05 #Python
浅谈MySQL中的触发器
May 05 #Python
You might like
php中设置index.php文件为只读的方法
2013/02/06 PHP
php解压文件代码实现php在线解压
2014/02/13 PHP
php上传图片获取路径及给表单字段赋值的方法
2016/01/23 PHP
Laravel下生成验证码的类
2017/11/15 PHP
PHP常用日期加减计算方法实例小结
2018/07/31 PHP
js实现权限树的更新权限时的全选全消功能
2009/02/17 Javascript
移动Web中图片自适应的两种JavaScript解决方法
2015/06/18 Javascript
javascript判断复选框是否选中的方法
2015/10/16 Javascript
Seajs是什么及sea.js 由来,特点以及优势
2016/10/13 Javascript
Vue 2.0中生命周期与钩子函数的一些理解
2017/05/09 Javascript
解决Angular2 router.navigate刷新页面的问题
2018/08/31 Javascript
[56:00]DOTA2上海特级锦标赛主赛事日 - 4 胜者组决赛Secret VS Liquid第一局
2016/03/05 DOTA
[04:19]DOTA2完美大师赛第四天精彩集锦
2017/11/26 DOTA
Python的内存泄漏及gc模块的使用分析
2014/07/16 Python
Python中使用异常处理来判断运行的操作系统平台方法
2015/01/22 Python
Python实现在线程里运行scrapy的方法
2015/04/07 Python
Python实现压缩与解压gzip大文件的方法
2016/09/18 Python
python中使用正则表达式的后向搜索肯定模式(推荐)
2017/11/11 Python
完美解决python3.7 pip升级 拒绝访问问题
2019/07/12 Python
Python中注释(多行注释和单行注释)的用法实例
2019/08/28 Python
Python json格式化打印实现过程解析
2020/07/21 Python
pycharm如何使用anaconda中的各种包(操作步骤)
2020/07/31 Python
Python实现七个基本算法的实例代码
2020/10/08 Python
IE下实现类似CSS3 text-shadow文字阴影的几种方法
2011/05/11 HTML / CSS
Parfume Klik丹麦:香水网上商店
2018/07/10 全球购物
英语系本科生个人求职信
2013/09/21 职场文书
资深财务管理人员自我评价
2013/09/22 职场文书
中学家长会邀请函
2014/02/03 职场文书
公司联欢晚会主持词
2014/03/22 职场文书
初中学生期末评语
2014/04/24 职场文书
银行求职信
2014/05/31 职场文书
大学生党员学习焦裕禄精神思想汇报
2014/09/10 职场文书
2014年军人思想汇报范文
2014/10/12 职场文书
博士给导师的自荐信
2015/03/06 职场文书
营业员岗位职责范本
2015/04/14 职场文书
GO中sync包自由控制并发示例详解
2022/08/05 Golang