存档

文章标签 ‘Apache’

Apache 2.x启用gzip压缩

2011年11月14日 sigma 没有评论 3,609 views

在2.x之后的apache,gzip压缩的模块改为了mod_deflate(原来是mod_gzip)。启用gzip压缩首先需要加载模块:

LoadModule deflate_module modules/mod_deflate.so

加载后需要简单的配置下(主要是对某些二进制文件不压缩,因为压缩效果差,并且会增加服务器负担)

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# Don’t compress
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
#Dealing with proxy servers
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>
分类: 杂七杂八 标签: ,

Linux下配置Python+Mysql+Apache+Django服务器

2011年9月10日 sigma 没有评论 7,596 views

为了便于叙述,我把配置过程写成一个脚本,按里面做就差不多了(请看懂脚本,再按里面一步一步做就差不多了):

 

# Install project
mv src /mnt/www

# Mount the EBS device
mkdir /mnt/ebs
mount /dev/sda1 /mnt/ebs

# Determine if mysql has already been set up on this device
first_time=0; [ -d /usr/bin/mysql ] || first_time=1
echo first_time=$first_time

# Install MySQL
yum -y install mysql-server

# Change the MySQL data directory
#sed -e 's!/var/lib/mysql$!/mnt/ebs/mysql!' -i /etc/my.cnf

# Tables should be InnoDB by default
echo -e "n[mysqld]ndefault-storage-engine=INNODB" >> /etc/my.cnf

# Prepare the MySQL database directory, if necessary
[ $first_time -eq 1 ] && mysql_install_db

# Start the MySQL server
service mysqld start

# Create a DB for Django, if necessary
[ $first_time -eq 1 ] && mysql -e "CREATE DATABASE django CHARACTER SET utf8"

# Install python development tools
yum -y install python-devel

# Install the Python-MySQL bridge
yum -y install MySQL-python

# Install Django
wget http://www.djangoproject.com/download/1.3/tarball/
tar -xzf Django-1.3.tar.gz
cd Django-1.3
python setup.py install
cd ..

# Cleanup
rm -f Django-1.3.tar.gz
rm -f -R Django-1.3

# Install Apache and mod_python
yum -y install httpd
yum -y install mod_python

#create a testsite
mkdir /mnt/www/src
cd /mnt/www/src/
django-admin.py startproject mysite
#edit settings.py
cd mysite
#edit settings.py following https://docs.djangoproject.com/en/dev/intro/tutorial01/
#syn db
python manage.py syncdb

#create models
python manage.py startapp polls

#add some models in polls/model.py

##add polls to settings file like
#INSTALLED_APPS = (
#    'django.contrib.auth',
#    'django.contrib.contenttypes',
#    'django.contrib.sessions',
#    'django.contrib.sites',
#    'polls'
#)

#add to database
python manage.py sql polls

#resync db
python manage.py syncdb
# Configure mod_python
# edit django.confi as following
#
## httpd config script for Django + mod_python
#
#<Location "/">
#         SetHandler python-program
#         PythonHandler django.core.handlers.modpython
#         SetEnv DJANGO_SETTINGS_MODULE mysite.settings
#         PythonOption django.root /mysite
#         PythonDebug On
#         PythonPath "['/mnt/www/src'] + sys.path"
#</Location>
cp django.conf /etc/httpd/conf.d

# Create symlink for Django admin static files
rm -r /var/www/html
ln -s /usr/lib/python2.6/site-packages/django/contrib/admin/media /var/www/html

# Start Apache
#httpd -k start
service httpd restart

# Sync Django to DB (always safe)
python /mnt/www/src/mysite/manage.py syncdb
#python /mnt/www/src/testsite/manage.py runserver 0.0.0.0 80

#test site
wget 127.0.0.1
分类: Web技术 标签: , , , ,

无觅相关文章插件,快速提升流量