red5下nginx安装配置

http://zfl110.iteye.com/blog/1155149

原址:http://lqw.iteye.com/blog/652763 
安装Nginx 

1.首先安装pcre-8.02.tar 否则 
执行完后会提示一个错误,说缺少PCRE library 这个是HTTP Rewrite 模块,也即是url静态化的包 
可上传pcre-8.02.tar.gz,输入如下命令安装: 

Java代码  收藏代码
  1. tar xzvf pcre-8.02.tar    
  2. ./configure    
  3. make    
  4. make install    





2.执行如下命令解压nginx: 


Java代码  收藏代码
  1. tar xzvf nginx-0.8.35.tar.gz    





3.编译安装nginx 

   

Java代码  收藏代码
  1. cd nginx-0.8.35    
  2.     ./configure --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module    





#启动server状态页和https模块 

   

Java代码  收藏代码
  1. --with-http_stub_status_module 必须加上,不然报unknown directive "stub_status"    
  2.         
  3.     make     
  4.         
  5.     make install    





4.nginx安装成功后的安装目录为/usr/local/nginx 
在conf文件夹中新建proxy.conf,用于配置一些代理参数,内容如下: 


   

Java代码  收藏代码
  1. #!nginx (-)     
  2.     # proxy.conf     
  3.     proxy_redirect          off;    
  4.     proxy_set_header        Host $host;    
  5.     proxy_set_header        X-Real-IP $remote_addr;  #获取真实ip    
  6.     #proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for; #获取代理者的真实ip    
  7.     client_max_body_size    10m;    
  8.     client_body_buffer_size 128k;    
  9.     proxy_connect_timeout   90;    
  10.     proxy_send_timeout      90;    
  11.     proxy_read_timeout      90;    
  12.     proxy_buffer_size       4k;    
  13.     proxy_buffers           4 32k;    
  14.     proxy_busy_buffers_size 64k;    
  15.     proxy_temp_file_write_size 64k;    




编辑安装目录下conf文件夹中的nginx.conf,输入如下内容: 

  

Java代码  收藏代码
  1. #--------------------------------------------    
  2.    #运行nginx所在的用户名和用户组     
  3.        
  4.    user nobody nobody;    
  5.        
  6.    #启动进程数    
  7.    worker_processes  2;    
  8.    worker_cpu_affinity 0010 0001 ;    
  9.    #worker_cpu_affinity 0001 0100 1000 0010 0001 0100 1000 0010;    
  10.        
  11.    #全局错误日志及PID文件     
  12.    error_log  /usr/local/nginx/logs/nginx_error.log  crit;     
  13.    pid  /usr/local/nginx/logs/nginx.pid;    
  14.    worker_rlimit_nofile 65535;    
  15.        
  16.    #工作模式及连接数上限    
  17.    events     
  18.    {    
  19.    use epoll;    
  20.    worker_connections 65535;    
  21.    }    
  22.        
  23.    #设定http服务器,利用它的反向代理功能提供负载均衡支持    
  24.    http{    
  25.    include       mime.types;    
  26.    default_type  application/octet-stream;    
  27.    server_names_hash_bucket_size 128;    
  28.        
  29.    #设定请求缓冲    
  30.    client_header_buffer_size 32k;    
  31.    large_client_header_buffers 4 32k;    
  32.    client_max_body_size 8m;    
  33.             
  34.    sendfile on;    
  35.    tcp_nopush     on;    
  36.    keepalive_timeout 60;    
  37.    tcp_nodelay on;    
  38.    fastcgi_connect_timeout 300;    
  39.    fastcgi_send_timeout 300;    
  40.    fastcgi_read_timeout 300;    
  41.    fastcgi_buffer_size 64k;    
  42.    fastcgi_buffers 4 64k;    
  43.    fastcgi_busy_buffers_size 128k;    
  44.    fastcgi_temp_file_write_size 128k;    
  45.        
  46.    #开启gzip模块    
  47.    gzip on;    
  48.    gzip_min_length  1k;    
  49.    gzip_buffers     4 16k;    
  50.    gzip_http_version 1.0;    
  51.    gzip_comp_level 2;    
  52.    gzip_types       text/plain application/x-javascript text/css application/xml;    
  53.    gzip_vary on;    
  54.        
  55.        
  56.    #设定负载均衡列表      
  57.    upstream  backend    
  58.    {      
  59.    #down 表示单前的server暂时不参与负载    
  60.    #weigth参数表示权值,权值越高被分配到的几率越大    
  61.    #server 192.168.3.69:80  weight=1;    
  62.    #max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误    
  63.    #fail_timeout:max_fails次失败后,暂停的时间。    
  64.    #backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。    
  65.        
  66.    server 172.16.50.147:8081;    
  67.    server 172.16.50.147:8082;     
  68.    server 172.16.50.147:8083;    
  69.    server 172.16.50.147:8084;    
  70.    }    
  71.        
  72.    #禁止通过ip访问站点    
  73.    #server{            
  74.    #server_name _;           
  75.    #return 404;         
  76.    #}     
  77.        
  78.    #设定虚拟主机    
  79.    server {    
  80.    listen 80;    
  81.    server_name localhost;    
  82.        
  83.    #对 / 所有做负载均衡 (本机nginx采用完全转发,所有请求都转发到后端的tomcat集群)    
  84.        
  85.    location / {      
  86.    #设定网站的资源存放路径     
  87.    root /var/www ;    
  88.    #设定访问的默认首页地址    
  89.    index index.jsp index.htm index.html;    
  90.    #proxy_pass  http://backend ;     
  91.    #保留用户真实信息    
  92.    include proxy.conf;    
  93.    proxy_set_header Host $host;    
  94.    proxy_set_header  X-Real-IP  $remote_addr;    
  95.    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;    
  96.        
  97.    #proxy_cache cache;    
  98.    #proxy_store on;    
  99.    proxy_temp_path /root/cache;    
  100.    proxy_cache_valid 200 302 24h;#200和302状态码保存1小时    
  101.    proxy_cache_valid 301 1d;#301状态码保存一天    
  102.    proxy_cache_valid any 10h;#其它的保存一分钟     
  103.    if ( !-f $request_filename) {    
  104.     proxy_pass  http://backend;    
  105.     }    
  106.    }    
  107.        
  108.    #状态监控部分    
  109.    location /nginx {      
  110.    stub_status on;    
  111.    access_log  on;     
  112.    auth_basic  "NginxStatus";     
  113.    auth_basic_user_file  /usr/local/nginx/htpasswd;     
  114.    #允许访问的ip allow   127.0.0.1;    
  115.    }     
  116.        
  117.    #定义访问日志的写入格式     
  118.    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '    
  119.    '$status $body_bytes_sent "$http_referer" '    
  120.    '"$http_user_agent" $http_x_forwarded_for';    
  121.    #设定访问日志的存放路径     
  122.    #access_log  /usr/local/nginx/logs/access.log  access;    
  123.    #设定access log    
  124.     access_log  logs/access.log  access;    
  125.     client_header_timeout  3m;    
  126.     client_body_timeout    3m;    
  127.     send_timeout           3m;    
  128.     sendfile                on;    
  129.     tcp_nopush              on;    
  130.     tcp_nodelay             on;    
  131.    #keepalive_timeout  65;  (这个参数如果启用,会出现未知错误,因此暂时取消)    
  132.        
  133.    }    
  134.    }    
  135.    #---------------------------------    






5.修改/usr/local/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确: 

 

Java代码  收藏代码
  1. #/usr/local/nginx/sbin/nginx -t   





如果屏幕显示以下两行信息,说明配置文件正确: 



   

Java代码  收藏代码
  1. the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok    
  2.     the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully    




如果提示unknown host,则可在服务器上执行:ping www.baidu.com如果也是同样提示unknown host则有两种可能: 
    a、服务器没有设置DNS服务器地址,查看/etc/resolv.conf下是否设置,若无则加上 
    b、防火墙拦截 



备注:conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可,如下: 


   

Java代码  收藏代码
  1. htpasswd -c /usr/local/nginx/htpasswd  admin    




输入密码: 

6、启动nginx的命令 

  

Java代码  收藏代码
  1. #/usr/local/nginx/sbin/nginx    





这时,输入以下命令查看Nginx主进程号: 

   

Java代码  收藏代码
  1. netstat -ntlp    
  2.          
  3.     ps -ef | grep nginx    






查看 Nginx 运行状态 

输入地址 http://172.16.50.147/nginx/,输入验证帐号密码,即可看到类似如下内容: 



   

Java代码  收藏代码
  1. Active connections: 328    
  2.         
  3.     server accepts handled requests    
  4.         
  5.     9309 8982 28890    
  6.         
  7.     Reading: 1 Writing: 3 Waiting: 324    






7、停止nginx的命令 


  

Java代码  收藏代码
  1. #/usr/local/nginx/sbin/nginx -s stop    





8,修改配置文件不停止服务,而重新加载新配置文件 


   

Java代码  收藏代码
  1. kill -HUP PID    
  2.         
  3.     #/usr/local/nginx/sbin/nginx -s reload    





8.纪念日把整站变成黑白色调 
在nginx.conf配置文件的http {...}大括号内增加以下两行: 


   

Java代码  收藏代码
    1. #sub_filter  '</head>'  '<style type="text/css">html {filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }</style></head>';    
    2.     #sub_filter_once on; 
原文地址:https://www.cnblogs.com/jukan/p/5290236.html