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,输入如下命令安装:

  1. tar xzvf pcre-8.02.tar
  2. ./configure
  3. make
  4. make install

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

  1. tar xzvf nginx-0.8.35.tar.gz

3.编译安装nginx

  1. cd nginx-0.8.35
  2. ./configure --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module

#启动server状态页和https模块

  1. --with-http_stub_status_module 必须加上,不然报unknown directive "stub_status"
  2. make
  3. make install

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

  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,输入如下内容:

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

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

  1. #/usr/local/nginx/sbin/nginx -t

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

  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 工具来产生即可,如下:

  1. htpasswd -c /usr/local/nginx/htpasswd  admin

输入密码:

6、启动nginx的命令

  1. #/usr/local/nginx/sbin/nginx

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

  1. netstat -ntlp
  2. ps -ef | grep nginx

查看 Nginx 运行状态

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

  1. Active connections: 328
  2. server accepts handled requests
  3. 9309 8982 28890
  4. Reading: 1 Writing: 3 Waiting: 324

7、停止nginx的命令

  1. #/usr/local/nginx/sbin/nginx -s stop

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

  1. kill -HUP PID
  2. #/usr/local/nginx/sbin/nginx -s reload

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

    1. #sub_filter  '</head>'  '<style type="text/css">html {filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }</style></head>';
    2. #sub_filter_once on;

red5下nginx安装配置的更多相关文章

  1. VMware Linux 下 Nginx 安装配置 - nginx.conf 配置 [负载两个 Tomcat] (三)

    首先启动Nginx 1. 相关浏览 两个 Tomcat 配置:  VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二) Nginx 安装配置启动: VMware Linu ...

  2. VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二)

    准备工作 相关浏览: VMware Linux 下 Nginx 安装配置 (一) 1. 选在 /usr/local/ 下创建 softs 文件夹,通过 ftp 命令 把 apache-tomcat-7 ...

  3. linux下Nginx 安装配置

    Nginx 安装 一.首先要安装 PCRE PCRE 作用是让 Ngnix 支持 Rewrite 功能. 1.下载 PCRE 安装包,下载地址: http://downloads.sourceforg ...

  4. CentOS 7服务器下Nginx安装配置

    一.安装编译工具及库文件 $ yum -y install make zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel pcre pc ...

  5. VMware Linux 下 Nginx 安装配置 (一)

    资源准备 1. pcre-8.34.tar.gz: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 2. zlib-1.2.8.tar.g ...

  6. centos7系统下nginx安装并配置开机自启动操作

    准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...

  7. linux系统下nginx安装目录和nginx.conf配置文件目录

    linux系统下nginx安装目录和nginx.conf配置文件目录 1.查看nginx安装目录 输入命令 # ps  -ef | grep nginx 返回结果包含安装目录 root      26 ...

  8. Nginx安装配置(转)

    Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...

  9. Linux下PHP安装配置MongoDB数据库连接扩展

    Web服务器: IP地址:192.168.21.127 PHP安装路径:/usr/local/php 实现目的: 安装PHP的MongoDB数据库扩展,通过PHP程序连接MongoDB数据库 具体操作 ...

随机推荐

  1. java类的加载以及初始化顺序

    类的加载和初始化的了解对于我们对编程的理解有很大帮助,最近在看类的记载方面的问题.从网上查阅了若干文章,现总结如下: 我们通过一段代码来了解类加载和初始化的顺序: package com.classl ...

  2. 10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

    The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk ...

  3. 关于ie6对齐

    先来没有任何对齐时的样子: 1.一种是在父级没有高度的情况下居中. 给每个独立的元素都加上vertical-align:middle; 针对文字可以不加,加与不加都可以居中对齐.但是无法做到绝对的居中 ...

  4. cbitmap 获取RGB CBitMap的用法

    MFC提供了位图处理的基础类CBitmap,可以完成位图(bmp图像)的创建.图像数据的获取等功能.虽然功能比较少,但是在对位图进行一些简单的处理时,CBitmap类还是可以胜任的.很多人可能会采用一 ...

  5. Android手动画柱状图的例子

    效果图如上,网上看到的例子,谨以此文记录一下,以后用到的地方再来翻翻. 核心技术是用Canvas和Paint画长方形. 源码地址:http://download.csdn.net/detail/abc ...

  6. 【转】IOS 计时器 NSTimer

    原文网址:http://blog.csdn.net/tangshoulin/article/details/7644124 1.初始化 + (NSTimer *)timerWithTimeInterv ...

  7. Xcode中使用svn时,报证书验证错误Error validating server certificate for

    转:http://blog.csdn.net/yhawaii/article/details/7511141 今天使用Xcode自带的svn客户端时,总是连接不上服务器,报如下错误: Error va ...

  8. sharepoint SPFolder的使用

    转:http://blog.csdn.net/pclzr/article/details/7591731 SPFolder是SharePoint对象模型中文件夹相关的类,它的使用方法相对比较简单.获取 ...

  9. [C++]cin读取回车键

    最近碰到一个问题,就是从控制台读取一组数,如: 12 23 34 56 若是使用 int data; while ( cin >> data ) {//...} 当回车后,不能有效转换到后 ...

  10. android 官网处理图片 代码

    /** * 获取压缩后的图片 (官网大图片加载对应代码) * * @param res * @param resId * @param reqWidth * 所需图片压缩尺寸最小宽度 * @param ...