手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Nginx实现负载均衡

[日期:2013-05-07] 来源:Linux社区  作者:jiajunfeng [字体:大 中 小]

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是否采用了该模块。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款