简介
Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,详细见百度
第一步:下载
下载地址:http://nginx.org/en/download.html,我选择的版本是nginx-1.10.3(如果版本不一致可能存在差异)。
下载下来压缩包为nginx-1.10.3.tar.gz。请使用tar -xzvf nginx-1.10.3.tar.gz解压
第二步:安装
进入Nginx解压目录,执行以下命令安装:
./configure && make && make install
默认安装目录为:/usr/local/nginx
第三步:配置
为了使得配置的server更加清晰,此处将每一个server单独剥离出来,场景如下:
有两台应用服务器,IP+PORT分别为:10.100.96.142:8080和10.100.96.143:8080,需配置轮询负载均衡
- 在/usr/local/nginx/conf下创建vhost目录,新建8080.xml(名字随意)文件
8080.xml配置如下:
server { listen 80; server_name 8080; #access_log logs/host.access.log main; location /ssm { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 location ~ .*$ { proxy_pass http://8080; } }配置/usr/local/nginx目录下的nginx.xml(注意upstream的配置,有需要可以加权重weight):
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; upstream 8080 { server 10.100.96.142:8080; server 10.100.96.143:8080; } include vhost/*.conf; }
第四步:启动Nginx
- 启动前检查,如果配置错误会提示
./sbin/nginx -t - 重启Nginx服务
查找当前nginx进程号,然后输入命令: ./sbin/nginx -s reload或kill -HUP 进程号 实现重启nginx服务
-
启动完成后,输入Nginx地址,如下即为成功


819



被折叠的 条评论
为什么被折叠?



