当前位置: > Linux服务器 > nginx >

nginx单机负载均衡测试配置文件macosx

时间:2016-10-06 19:19来源:linux.it.net.cn 作者:IT

马上要做个联网的东东,需要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()的内容

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容