nginx单机负载均衡测试配置文件 mac os x

马上要做个联网的东东,需要nginx做服务器。这样负载均衡啊啥的就不用管啦大笑


#user  nobody;
worker_processes  1;
error_log  /Users/lingyun/www/log/error.log;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;

	#upstream设置。默认监听80端口,提供给客户端的地址也是这个
	upstream myproject
	{
		server 127.0.0.1:8000;
		server 127.0.0.1:8001;
	}
	server
	{
		listen 80;
		server_name localhost;
		location / {
			proxy_pass http://myproject;
		}
	}



    #真正的web服务器配置。简单起见,这里两个web服务器配置的路径是一致的,除了端口。这些地址不需要开放给客户端
   
    server {
        listen       8000;
        server_name  localhost;

	location / {
            root   /Users/lingyun/www/ko32example/site;
            index  index.html index.htm;
        }

	 location ~ \.php$ {
            root           /Users/lingyun/www/farm/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /Users/lingyun/www/farm/public$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    server {
        listen       8001;
        server_name  localhost;

	location / {
            root   /Users/lingyun/www/ko32example/site;
            index  index.html index.htm;
        }

	 location ~ \.php$ {
            root           /Users/lingyun/www/farm/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /Users/lingyun/www/farm/public$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

后面在多台机器启动web服务器的时候,修改下这个配置就行了(还没测试)。现在先在单机上跑通流程就行啦。

环境安装相关的google百度下就行:)

浏览器验证

http://localhost/test.php

http://localhost:8000/test.php

http://localhost:8001/test.php

都能返回phpinfo()的内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值