安装 Nginx 配置负载均衡
来源:互联网 发布:审计公司采集数据软件 编辑:程序博客网 时间:2024/05/17 23:24
安装 Nginx 配置负载均衡
据说 Nginx 做负载均衡不错,恩拿来学习配置下。
先安装:
- wget http://sysoev.ru/nginx/nginx-0.6.35.tar.gz
- tar zxvf nginx-0.6.35.tar.gz
- cd nginx-0.6.35
- ./configure
- make
- make install
安装时出现下面的错误:
Configuration summary
+ PCRE library is not found
+ OpenSSL library is not used
+ md5 library is not used
+ sha1 library is not used
+ using system zlib library./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
说没有 PCRE 库,那安装它:
- yum install pcre-devel
安装完后,修改配置vi conf/nginx.conf,修改后看起来像:
- user chenlb;
- worker_processes 10;
- #error_log logs/error.log;
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid;
- events {
- use epoll;
- 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;
- #gzip on;
- upstream demo {
- server 172.0.0.1:8080 weight=1;
- server 192.168.1.100:8080 weight=1;
- }
- server {
- listen 80;
- server_name nobody.chenlb.com;
- #charset koi8-r;
- log_format nobody_chenlb_com '$remote_addr - $remote_user [$time_local] $request '
- '"$status" $body_bytes_sent "$http_referer" "$http_x_forwarded_for"';
- access_log logs/access.log nobody_chenlb_com;
- location / {
- proxy_pass http://demo;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- }
- }
修改浏览器所在机子hosts,nobody.chenlb.com 指向到nginx所在机子。
jsp的测试页面,nginx-test.jsp:
- <%@ page language="java" pageEncoding="UTF-8"%>
- <%@ page import="java.util.LinkedHashMap" %>
- <%@ page import="java.util.Enumeration" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>nginx demo</title>
- </head>
- <body>
- <%
- LinkedHashMap map = new LinkedHashMap();
- map.put("getServerName", request.getServerName());
- map.put("getServerPort", request.getServerPort());
- map.put("getRemoteAddr", request.getRemoteAddr());
- map.put("getRemoteHost", request.getRemoteHost());
- map.put("getRemotePort", request.getRemotePort());
- map.put("getLocalName", request.getLocalName());
- map.put("getLocalAddr", request.getLocalAddr());
- map.put("getLocalPort", request.getLocalPort());
- //HttpServletRequest req = (HttpServletRequest)request;
- for (Enumeration e = request.getHeaderNames() ; e.hasMoreElements() ;) {
- Object obj = e.nextElement();
- map.put(obj.toString(), request.getHeader(obj.toString()));
- }
- %>
- <table border=1>
- <tr><th>name</th><th>value</th></tr>
- <%
- for(Object key : map.keySet()) {
- out.println("<tr><th>");
- out.println(key+"</th><th>"+map.get(key)+"</th></tr>");
- }
- String str = request.getContextPath()+request.getServletPath()+(request.getPathInfo()==null?"":request.getPathInfo())+(request.getQueryString() == null ? "" : "?"+request.getQueryString());
- System.out.println(str);
- %>
- </table>
- </body>
- </html>
分别在172.0.0.1:8080、192.168.1.100:8080的web实例(webapps/demo)下放入nginx-test.jsp。
启动nginx:
- sbin/nginx
在浏览器中访问:http://nobody.chenlb.com/demo/nginx-test.jsp,出现了一个问题,一时快,一时很慢,看到nginx在域名查找,后来把upstream的demo在nginx那台机子的hosts配上IP就好。
- 安装 Nginx 配置负载均衡
- nginx安装及负载均衡配置
- Linux Ubuntu Nginx负载均衡 安装 配置
- Nginx安装及负载均衡配置
- ubuntu安装nginx及负载均衡配置
- CentOs nginx 安装 及 负载均衡配置
- linux安装nginx并且配置负载均衡
- centos安装nginx,配置负载均衡
- Nginx安装与负载均衡配置
- nginx的安装和负载均衡配置
- nginx 负载均衡配置
- nginx配置负载均衡
- nginx负载均衡配置
- Nginx负载均衡配置
- Nginx负载均衡配置
- Nginx负载均衡配置
- nginx负载均衡配置
- Nginx 负载均衡配置
- 查看系统信息(cpu,内存,硬盘,网卡)
- ICE应用小程序
- mongodb入门-7 查询2
- 解决android logcat不打印信息
- Struts2使用DoubleSelect实现二级级联下拉框省份城市
- 安装 Nginx 配置负载均衡
- 文本编辑器<三>更好的滚动条
- JQuery、JSON、Ajax在Servlet中的应用
- 黑马程序员——面向对象1
- Mel中级教程精华篇预告
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- php安装加速扩展 APC 详解
- Php开发任职要求
- android调用系统自带应用--如拨号