顯示具有 apache 標籤的文章。 顯示所有文章
顯示具有 apache 標籤的文章。 顯示所有文章

2014年5月30日 星期五

Apache 允許特定網段

多個網段以空格分開
Order Allow,Deny
Allow from 192.168.16.0/24 192.168.20.0/24
 
 
 
Allow, Deny 順序 
Match      | Allow,Deny result   | Deny,Allow result
-------------------------------------------------------
Allow only | Allowed             | Allowed
Deny only  | Denied              | Denied
No match   | Default: Denied     | Default: Allowed
Match both | Final match: Denied | Final match: Allowed 
 
 
 
 
References : 
Apache httpd: How can I Deny from all, Allow from subnet, but Deny from IP within that subnet? - Server Fault

2014年4月7日 星期一

CentOS compile moswsgi with Python 2.7

# yum install mercurial httpd-devel
$ hg clone https://code.google.com/p/modwsgi/
$ cd modwsgi/mod_wsgi
$ ./configure --with-apxs=/usr/sbin/apxs --with-python=/usr/local/bin/python2.7
$ make
# make install
# vi /etc/httpd/conf/httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so




References :
Running our Django site with mod_wsgi and virtualenv (part 2) | techno milk

2014年3月25日 星期二

mod_wsgi automatic reload on source code change

Adding the WSGIScriptReloading directive meant that any time I made changes to my application files, I could simply $  touch flaskTest.wsgi and the app would restart with changes applied.
 
# vi /etc/apache2/sites-enabled/000-default.conf 
<VirtualHost *:80>
    ServerName flasktest.subdimension.co.uk

    WSGIDaemonProcess flaskTest user=flask group=www-data threads=5 home=/<redacted>/flaskTest
    WSGIScriptAlias / /<redacted>/flaskTest/flaskTest.wsgi

    <Directory /<redacted>/flaskTest>
        WSGIProcessGroup flaskTest
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

$ touch /<redacted>/flaskTest/flaskTest.wsgi




References :
Deploying Flask to Apache » subdimension

2014年2月23日 星期日

Flask with Apache and mod_wsgi

Debian / Ubuntu:
# apt-get install python-setuptools
# easy_install pip
# cd /var/www
# git clone https://github.com/salimane/flask-mvc.git
# cd flask-mvc
# pip install -r requirements.txt
# vi application.wsgi
import sys                                                                                                         
sys.path.insert(0,'/var/www/flask-mvc')
from project import app as application
# apt-get install libapache2-mod-wsgi
# vi /etc/apache2/sites-enabled/000-default.conf
        WSGIDaemonProcess flaskapp user=www-data group=www-data threads=5
        WSGIScriptAlias /flask-mvc /var/www/flask-mvc/application.wsgi

       
                WSGIProcessGroup flaskapp
                WSGIApplicationGroup %{GLOBAL}
                Order deny,allow
                Allow from all
       
# /etc/init.d/apache2 restart

http://0.0.0.0/flask-mvc


CentOS :

# yum install python-setuptools
# easy_install pip
# cd /var/www/html
# git clone https://github.com/salimane/flask-mvc.git
# cd flask-mvc
# pip install -r requirements.txt
# vi application.wsgi
import sys
sys.path.insert(0,'/var/www/html/flask-mvc')
from project import app as application
# yum install mod_wsgi
# vi /etc/httpd/conf/httpd.conf
WSGIDaemonProcess flaskapp user=www-data group=www-data threads=5
WSGISocketPrefix run/wsgi
WSGIScriptAlias /flask-mvc /var/www/html/flask-mvc/application.wsgi

    WSGIProcessGroup flaskapp
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
# /etc/init.d/httpd restart




References :
mod_wsgi (Apache) — Flask 0.11-dev documentation
Deploying Flask Apps with Apache and Mod WSGI - Informatics Bridging Team - Ocean Imaging Informatics @ WHOI

2013年12月13日 星期五

Apache rewrite module with POST parameters

httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so

RewriteEngine On
RewriteRule project/(index.php.*) http://192.168.1.2/project/%1 [R=301,P]
 



References :
为Apache rewrite转发添加POST数据支持Alex's blog | Alex's blog
HTTP POST请求的Apache Rewrite规则设置 - slvher的专栏 - 博客频道 - CSDN.NET

2012年12月26日 星期三

Apache Multi-Processing Module (MPM)

prefork :
non-threaded
pre-forking
耗費較多記憶體
速度較 worker 快
一般使用 prefork,他可以使用不支持 Thread-Safe 的模組








worker :
multi-threaded
multi-process
耗費較少記憶體
適用於多 HTTP request
worker mpm一般不会跟mod php搭配, worker mpm一般都是跟apache的mod fcgid 搭配,然后php要安装php-cgi 来跑php的.



# apachectl -l




Reference :
Apache的prefork模式和worker模式 - 平凡的世界
Apache mpm 模組的 worker 和 prefork 差別為何 ? 

2012年6月8日 星期五

Apache 2 安全性設定

# vi /etc/apache2/conf.d/security
ServerSignature Off
ServerTokens Prod

2012年4月5日 星期四

Apache 虛擬主機

# vi /etc/apache2/sites-enabled/000-default
NameVirtualHost 172.20.30.40:81


DocumentRoot /www/example1
ServerName www.example1.com



DocumentRoot /www/example2
ServerName www.example2.org




Reference :
VirtualHost Examples - Apache HTTP Server

2011年10月25日 星期二

Linux Apache server rotate and analize log

使用 cronolog 將日誌依 "日" 或 "星期" 分開
# vi /etc/apache2/sites-enabled/000-default
=========================================================
CustomLog "|/usr/sbin/cronolog /var/log/apache2/access.log.%Y-%m-%d" combined
=========================================================


將多台機器的日誌送至同一台合併
$ cat log1 log2 log3 > log_all

使用日誌需要排序, 日期、時間欄位要是數字的, 否則, 日誌最少要跨月儲存, 不然排序可能有問題
$ sort -m -t " " -k 4 -o log_all log1 log2 log3
       -m, --merge
              merge already sorted files; do not sort


用 awstat 可以直接合併多檔案
# vi /etc/awstats/awstats.SITE_DOMAIN.conf
=========================================================
LogFile="/usr/share/doc/awstats/examples/logresolvemerge.pl /var/log/apache2/access.log.2011-* |"
=========================================================

使用 awstats 分析 log
# /usr/lib/cgi-bin/awstats.pl -config=SITE_DOMAIN -update
// 可以放到 cron 去跑
# vi /etc/crontab
5,35 * * * * /usr/lib/cgi-bin/awstats.pl -config=SITE_DOMAIN -update




Reference :
The Will Will Web | Apache log rotate 的另一個選擇:cronolog
多服务器的日志合并统计——apache日志的cronolog轮循
AWStats — 多功能記錄檔分析工具 - OpenFoundry
ubuntu 安裝 awstats 分析網站流量 @ 卡卡的程式部落格 :: 痞客邦 PIXNET :: 
AWStats Documentation - Other tools