1.9 虚拟主机的建立
# cd /usr/local/nginx/conf/vhost/
# vim default.conf
*********************************************************************
server
{
listen 80;
#本机域名或IP
server_name server3_3.example.com
index index.html index.php;
root /home/www;
location /nginx{
stub_status on;
auth_basic "NginxStatus";
#auth_basic_user_file conf/htpasswd;
#密码是由apache的htpasswd工具产生
access_log off;
}
location / {
location ~ .*/.(php|php5)?$ {
index index.php;
root /home/www/;
proxy_pass http://127.0.0.1:81;
}
include proxy.conf;
if ( !-e $request_filename){
proxy_pass http://127.0.0.1:81;
}
location ~* /.(jpg|jpeg|gif|png|swf)$ {
if ( -f $request_filename ){
root /home/www/;
expires 30d;
break;
}
}
location ~* /.(jss|css)$ {
if (-f $request_filename){
root /home/www/;
expires 1d;
break;
}
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html{
root html;
}
#如果需要记录就把下面的注释去掉
# log_format access '$http_x_forwarded_for - $remote_user [$time_local] "$request"'
# '$status $body_bytes_sent "$http_referer"'
# '"$http_user_agent" $remote_addr';
# access_log logs/IP_access.log access;
}
*********************************************************************
注意,配置文件中,每个“server”即就一台主机~
# /etc/init.d/nginx start #启动Nginx
此时,对应关系如下:
server3.example.com——>/usr/local/nginx/html/index.html
server3_3.example.com——>/home/www/index.html
虚拟主机OK了! 多个虚拟主机复制并修改以上内容即可~
顺便提一句:
可以利用tcmalloc优化MySQL数据库喔!
# vim /etc/init.d/mysqld
添加:export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
重启mysql数据库
# lsof -n|grep tcmalloc 可以查看mysql是否采用了该模块。
