nginx 配置

1,worker_processes cpu*核数;#工作进程数

2,events {
    worker_connections  1024;

}#最大连接数

3,日志

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';#系统默认的日志格式
 log_format   simple '$remote_addr------------$remote_user[$time_local]"$request"'
                         '"$http_user_agent" "$http_x_forwarded_for"';#simple 自命名格式

#access_log  logs/access.log  simple;#默认使用格式

相关说明解释

 1.$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;
 2.$remote_user :用来记录客户端用户名称;
 3.$time_local : 用来记录访问时间与时区;
 4.$request : 用来记录请求的url与http协议;
 5.$status : 用来记录请求状态;成功是200,
 6.$body_bytes_s ent :记录发送给客户端文件主体内容大小;
 7.$http_referer :用来记录从那个页面链接访问过来的;

 8.$http_user_agent :记录客户端浏览器的相关信息;

4,rewrite

location / {
            root   /var/www/maiji/yii/basic/web;
            index  index.php index.html index.htm;
            if (!-e $request_filename ){#!-e $request_filename:路径下的文件、文件夹不存在
              rewrite ^/(.*)$ /index.php?r=$1 last;#从写到指定路径下
            }
        }

5,动静分离

location ~ \.(jpg|png|gif|jpeg)${

proxy_pass   http://ip:port;

}

6,负载均衡,集群

upstream testserver{

server  192.168.1.2:80 weight=1 max_fail=2 fail_timeout=30s

server  192.168.1.3:80 weight=1 max_fail=2 fail_timeout=30s

server  192.168.1.4:80 weight=1 max_fail=2 fail_timeout=30s

}

1,负载均衡策略要做到:session 共享

PHP.ini设置session保存路径

session.save_handler = redis

session.save_path ="tcp://localhost:6379",

2,每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。

#--问题是达不到觉对的均衡 

upstream backserver { 
ip_hash; 
server 192.168.0.14:88; 
server 192.168.0.15:80; 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值