Nginx基本使用方法及各模块基本功能

一、Nginx介绍

Nginx是由俄罗斯软件工程师Igor Sysoev开发的一个高性能的HTTP和反向代理服务器,具备IMAP/POP3和SMTP服务器功能,Nginx最大的特点是对高并发的支持和高效的负载均衡,在高并发的需求场景下,是Apache服务器不错的替代品。目前,包括新浪、腾讯等知名网站都已使用Nginx作为Web应用服务器。下面我简单介绍一下:

nginx是一个高性能的Web和反向代理服务器,它具有很多非常优越的特性;

作为Web服务器;相比较与Apache,Nginx使用更少的资源,支持更多的并发连接,体现更高的效率,这点使Nginx尤为受到虚拟主机提供商的欢迎,能够支持高达50000个并发的连接数的响应。

作为负载均衡服务器器:Nginx既可以在内部直接支持Rails和PHP,也可以支持作为HTTP代理服务器对外惊醒服务,Nginx用C语言编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。

作为邮件代理服务器,Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last.fm描述了成功并且美妙的使用经验。

Nginx安装非常简单,配置文件非常简介(还能够支持perl语法),Bugs非常少的服务器:Nginx启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数月也不需要重新启动。还能够在不间断服务的情况下进行软件版本平滑升级。

二、软件获得及帮助文档

官方地址:http://nginx.org

下载稳定版本:http://nginx.org/download/nginx-1.8.0.tar.gz

帮助文档:http://nginx.org/en/docs

编译参数说明:http://nginx.org/en/docs/configure.html

三、Nginx的功能

1、Nginx的特性
   模块化设计、较好的扩展性
   高可靠性:一个master启动一或多个worker,每个worker响应多个请求
   低内存消耗:10000个keepalive连接在Nginx中仅消耗2.5MB内存(官方数据)
   支持热部署:不停机更新配置文件、更新日志文件、更新服务器程序版本
   
2、Nginx的基本功能
   静态web资源服务器,能够缓存打开的文件描述符
   支持http/imap/pop3/smtp的反向代理;支持缓存、负载均衡
   支持fastcgi(fpm)
   模块化,非DSO机制,支持过滤器zip压缩,SSI以及图像大小调整
   支持SSL
   
3、Nginx的扩展功能
   基于名称和IP的虚拟主机
   支持keepalive的保持机制
   支持平滑升级
   定制访问日志,支持使用日志缓存区提高日志存储性能
   支持url rewrite
   支持路径别名(root或alias指定)
   支持基于IP以及用户的访问控制
   支持传输速率限制,并发限制
   
4、Nginx的基本架构
   一个master进程,生成一个或者多个worker进程,每个worker响应多个请求
   事件驱动:epoll,kqueue,poll,select,rt signals
   支持sendfile,sendfile64
   支持AIO
   支持mmap
   
5、Nginx模块类型
   Nginx core module: nginx的核心模块
   Standard HTTP modules:nginx的标准模块
   Optional HTTP modules:nginx的可选模块
   Mail modules :nginx的邮件模块
   3rd party modules:nginx的第三方模块
   
6、Nginx进程详解

   主进程主要完成如下工作:
       读取并验正配置信息;
       创建、绑定及关闭套接字;
       启动、终止及维护worker进程的个数;
       无须中止服务而重新配置工作特性;
       控制非中断式程序升级,启用新的二进制程序并在需要时回滚至老版本;
       重新打开日志文件,实现日志滚动;
       编译嵌入式perl脚本;
       worker进程主要完成的任务包括:
       接收、传入并处理来自客户端的连接;
       提供反向代理及过滤功能;
       nginx任何能完成的其它任务;
    
   cache loader进程主要完成的任务包括:
       检查缓存存储中的缓存对象;
       使用缓存元数据建立内存数据库;
    
   cache manager进程的主要任务:
       缓存的失效及过期检验;

四、Nginx安装配置

1、安装依赖包(CentOS 6.7)
[[email protected] soft]# yum -y groupinstall "Development tools,Server platform development,Desktop platform development"
[[email protected] soft]# yum -y install pcre-devel openssl-devel

2、编译安装Nginx
[[email protected] soft]# tar xf nginx-1.8.0.tar.gz 
[[email protected] soft]# cd nginx-1.8.0
[[email protected] nginx-1.8.0]# groupadd -r nginx
[[email protected] nginx-1.8.0]# useradd -g nginx -s /sbin/nologin -M nginx
[[email protected] nginx-1.8.0]# ./configure    --prefix=/usr/local/nginx    --sbin-path=/usr/sbin/nginx    --conf-path=/etc/nginx/nginx.conf    --error-log-path=/var/log/nginx/error.log    --http-log-path=/var/log/nginx/access.log    --pid-path=/var/run/nginx/nginx.pid     --lock-path=/var/lock/nginx.lock    --user=nginx    --group=nginx    --with-http_ssl_module    --with-http_flv_module    --with-http_stub_status_module    --with-http_gzip_static_module    --http-client-body-temp-path=/var/tmp/nginx/client/    --http-proxy-temp-path=/var/tmp/nginx/proxy/    --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/    --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi    --http-scgi-temp-path=/var/tmp/nginx/scgi    --with-pcre
 [[email protected] nginx-1.8.0]# make && make install
     
 ##注意:编译后有些文件夹不会自动创建

[[email protected] nginx-1.8.0]# mkdir -pv /var/tmp/nginx/{client,proxy,fcgi,uwsgi,scgi}
mkdir: created directory `/var/tmp/nginx‘
mkdir: created directory `/var/tmp/nginx/client‘
mkdir: created directory `/var/tmp/nginx/proxy‘
mkdir: created directory `/var/tmp/nginx/fcgi‘
mkdir: created directory `/var/tmp/nginx/uwsgi‘
mkdir: created directory `/var/tmp/nginx/scgi‘

这里的二进制文件是直接指定在PATH环境变量里面的,所有可以直接使用,不用导出:

配置vim,使其编辑nginx配置文件时语法着色,默认没有
[[email protected] nginx-1.8.0]# cd 
[[email protected] ~]# mkdir .vim
[[email protected] ~]# cp -ra /u01/soft/nginx-1.8.0/contrib/vim/* .vim
[[email protected] ~]# ls .vim
ftdetect  indent  syntax

编写启动脚本:
[[email protected] ~]# vim /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse #               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# pidfile:     /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
   [ -x $nginx ] || exit 5
   [ -f $NGINX_CONF_FILE ] || exit 6
   echo -n $"Starting $prog: "
   daemon $nginx -c $NGINX_CONF_FILE
   retval=$?
   echo
   [ $retval -eq 0 ] && touch $lockfile
   return $retval
}
stop() {
   echo -n $"Stopping $prog: "
   killproc $prog -QUIT
   retval=$?
   echo
   [ $retval -eq 0 ] && rm -f $lockfile
   return $retval
}
restart() {
   configtest || return $?
   stop
   start
}
reload() {
   configtest || return $?
   echo -n $"Reloading $prog: "
   killproc $nginx -HUP
   RETVAL=$?
   echo
}
force_reload() {
   restart
}
configtest() {
 $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
   status $prog
}
rh_status_q() {
   rh_status >/dev/null 2>&1
}
case "$1" in
   start)
       rh_status_q && exit 0
       $1
       ;;
   stop)
       rh_status_q || exit 0
       $1
       ;;
   restart|configtest)
       $1
       ;;
   reload)
       rh_status_q || exit 7
       $1
       ;;
   force-reload)
       force_reload
       ;;
   status)
       rh_status
       ;;
   condrestart|try-restart)
       rh_status_q || exit 0
           ;;
   *)
       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-
reload|configtest}"
       exit 2
esac

[[email protected] ~]# chmod +x /etc/rc.d/init.d/nginx   #添加可执行权限
[[email protected] ~]# chkconfig --add nginx   #添加到服务列表
[[email protected] ~]# chkconfig nginx on      #设置开机自启动

[[email protected] ~]# service nginx start   #启动nginx
Starting nginx:                                            [  OK  ]
[[email protected] ~]# ss -tnl     #查看是否监听80端口
[[email protected] ~]# ss -tnl
State       Recv-Q Send-Q                Local Address:Port                  Peer Address:Port 
LISTEN      0      128                               *:80                               *:*     
LISTEN      0      128                              :::22                              :::*     
LISTEN      0      128                               *:22                               *:* 
##查看页面
[[email protected] ~]# curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
#######################编译安装已经完成。

配置文件介绍
  主要有两部分:分别是
    main:主体部分
    http{}:虚拟主机配置部分
    
   配置指令主要以分号结尾;配置语法:directive value1 [value2 ....]
   支持使用的变量
       模块内置的变量
       自定义变量:set var_name value
   
   主配置段的指令类别:
  用于调试和定位问题:
   (1)daemon [on|off]:  是否以守护进程的方式启动nginx;
   (2)master_press [on|off]:  是否以master/worker模型来运行nginx;
   (3)error_log /path/to/error_loglevel:  指明错误日志文件级别,处于调试目的,可以使用debug级别,但次级别只有在编译nginx时使用了--with-debug选项才有效 ;
       
  正常运行必备的配置:
   (1)user USERNAME [GROUPNAME]:指定运行worker的用户和用户组;例如 user nginx nginx 
   (2)pid /path/to/nginx.pid : 指定pid文件
   (3)worker_rlimit_nofile # : 指定一个worker进程能够打开的最大文件句柄数
   (4)worker_rlimit_sigpending # : 指定每个用户能够发往worker信号的数量
       
  优化性能相关的配置:
   (1)worker_processes # :worker进程的个数,通常是cpu核心数减1
   (2)worker_cpu_affinity cpuumask :绑定worker进程至指定的CPU上
   (3)timer-resolution t :时间解析度,在x86服务器上可以不用配置
   (4)worker_priority NICE :调整nice值(-20,19);nice值越大,越优先分配cpu
       
  事件相关的配置;
   (1)accept_mutex [on|off] :内部调动用户请求至各worker时的负载均衡锁;启用时表示能够让多个worker轮流的、序列化的响应请求
   (2)lock_file /path/to/lock_file :指定锁文件
   (3)accept_mutex_delay #ms: 取得负载均衡锁的时间
   (4)use [epoll|poll|select|rgsig]:定义使用的事件模型,建议让nginx自动选择
   (5)worker_connections #:每个worker进程所能够响应的最大并发请求数

五、Nginx的一些基本功能实现

1、基于用户认证:
(1)、修改配置文件
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        auth_basic "www.bjwf125.com";
        auth_basic_user_file /www/html/.passwd;
        }
 }
(2)、创建文档根目录以及使用httpd-tools中的htpasswd工具创建用户
[[email protected] ~]# mkdir -pv /www/html
mkdir: created directory `/www‘
mkdir: created directory `/www/html‘
[[email protected] ~]# echo "Welcome to bjwf125" > /www/html/index.html
[[email protected] ~]# yum -y install httpd-tools
[[email protected] ~]# htpasswd -c -m /www/html/.passwd centos    #创建centos用户
New password:                                    #输入密码
Re-type new password:                            #再次输入
Adding password for user centos
(3)、重新载入配置文件
[[email protected] ~]# nginx -t    #检查Nginx语法
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[[email protected] ~]# service nginx reload     #重新载入

2、基于IP认证
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        deny 192.168.9.0/24;
        allow all;
        }
 }
 3、基于gzip压缩
 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /www/html;
            index  index.html index.htm;
        gzip on;
        gzip_http_version 1.0;
        gzip_min_length 1000;
        gzip_proxied expired no-cache no-store private auth;
        gzip_types text/plain application/xml text/css application/x-javascript text/xml
             application/xml+rss text/javascript application/javascript application/json;
        gzip_disable msie6 safari;

        }
 }
[[email protected] ~]# nginx -t
[[email protected] ~]# service nginx reload
[[email protected] ~]# cp /etc/rc.d/rc.sysinit /www/html/zip.html
[[email protected] ~]# ll /www/html/zip.html -h
-rwxr-xr-x 1 root root 20K Jan 13 10:01 /www/html/zip.html

4、定制响应头部
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /www/html;
            index  index.html index.htm;
        expires 24h;
        add_header bjwf125 mymail;
        }
}
[[email protected] ~]# nginx -t
[[email protected] ~]# service nginx reload

5、URL重定向
   语法格式:
   rewrite grgex replacement [flages]
   flages
   last:一旦被当前规则匹配并重写后立即停止检查其他后续的rewrite的规则,而后通过重写后的规则重写发起请求;
   bleak:一旦被当前规则匹配并重写后立即停止后续的其他rewrite的规则,而后由nginx进行后续操作;
   redirect:返回302临时重定向
   permanent:返回301永久重定向
例如:
[[email protected] ~]# vim /etc/nginx/nginx.conf
 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /www/html;
            index  index.html index.htm;
        rewrite ^/admin/(.*)$ /web/$1;
        }
  }
  
[[email protected] ~]# mkdir -pv /www/html/{admin,web}
[[email protected] ~]# echo "mail.bjwf125.com" > /www/html/web/index.html
[[email protected] ~]# nginx -t
[[email protected] ~]# service nginx reload

6、虚拟主机
[[email protected] nginx]# vim /etc/nginx/nginx.conf
#注释掉http{}段中的预定义server{}段中的所有内容;
在文件末尾}前一行添加一条:
include conf.d/nginx-vhost.conf;
#方便后面定义,根据个人习惯而已,也可以直接在/etc/nginx/nginx.conf中配置
[[email protected] nginx]# vim /etc/nginx/conf.d/nginx-vhost.conf 
server {
   listen       80;
   server_name  www.a.com;
        
   location / {
        root    /www/html/a;
        index   index.html index.htm;
        }
}
 
server {
   listen       80;
   server_name  www.b.com;
        
   location / {
        root    /www/html/b;
        index   index.html index.htm;
        }
}

[[email protected] nginx]# mkdir /www/html/{a,b} -pv
mkdir: created directory `/www/html/a‘
mkdir: created directory `/www/html/b‘
[[email protected] nginx]# echo "www.a.com" > /www/html/a/index.html
[[email protected] nginx]# echo "www.b.com" > /www/html/b/index.html
[[email protected] nginx]# vim /etc/hosts
192.168.9.9     www.a.com
192.168.9.9     www.b.com
[[email protected] nginx]# service nginx reload
[[email protected] nginx]# curl http://www.a.com
www.a.com
[[email protected] nginx]# curl http://www.b.com
www.b.com
###虚拟主机最简单的方式已经配置完成,但是虚拟主机里面还有很多参数。
7、防盗链
(1)、定义合规的引用
        valid_referers none | blocked | server_names | string ...;
 (2)、拒绝不合规的引用
         if ($invalid referer) {
          rewrite ^/ http://www.b.com/403.html;
         }
  ##具体示例如下:
  [[email protected] conf.d]# vim nginx-vhost.conf
   server {
   listen       80;
   server_name  www.b.com;
        
   location / {
        root    /www/html/b;
        index   index.html index.htm;
        valid_referers none blocked www.b.com *.b.com;
        if ($invalid_referer) {
        rewrite ^/ http://www.b.com/403.html;
        }
      }
   } 
   
   [[email protected] conf.d]# vim /www/html/a/index.html
   www.a.com
   <img src="http://www.b.com/images/1.jpg">   #在a.com中引用
    [[email protected] conf.d]# vim /www/html/b/index.html
   www.b.com
   <img src="http://www.b.com/images/1.jpg">   #b.com自己引用

测试结果:

8、Nginx的反向代理
   Nginx可以通过proxy模块实现反向代理功能,在作为web反向代理服务器时,Nginx复制接收客户端请求,并能够根据URL、客户端参数或者其它的处理逻辑将用户请求调度至上游服务器上(upstream server)。
   Nginx在实现反向代理功能时最重要的指令为proxy_pass,它能够将location中定义的某URI代理至指定的上游服务器(组)上。如下面的示例中,location的URI将被替换为上游服务器上的newURI。
### 例如:
[[email protected] conf.d]# vim nginx-vhost.conf 
server {
   listen       80;
   server_name  www.a.com;
   add_header X-Via $server_addr;

   location / {
        root    /www/html/a;
        index   index.html index.htm;
        }
   location = /node2 {
        proxy_pass http://192.168.9.11/;
        }
}
##上游服务器必须要配置相应服务及页面
[[email protected] conf.d]# service nginx reload
[[email protected] conf.d]# curl  www.a.com
<img src="http://www.b.net/images/1.jpg"> 
[[email protected] conf.d]# curl http://www.a.com/node1
node1.bjwf125.com

(1)、缓存:Nginx作为反向代理时,能够将上游服务器的响应缓存至本地,并在后续的客户端请求同样的内容时直接从本地构造响应报文。具体参数如下:
    proxy_cache zone|off:定义一个用于缓存的共享内存区域,其可被多个地方调用;
    proxy_cache_path:定义一个保存缓存响应报文的目录,及一个保存缓存对象的键及响应元数据的共享内存区域(keys_zone=name:size),其可选参数有:
          levels:每级子目录名称的长度,有效值为1或2,每级之间使用冒号分隔,最多为3级;
          inactive:非活动缓存项从缓存中剔除之前的最大缓存时长;
          max_size:缓存空间大小的上限,当需要缓存的对象超出此空间限定时,缓存管理器将基于LRU算法对其进行清理;
          loader_files:缓存加载器(cache_loader)的每次工作过程使用为多少个文件加载元数据;
          loader_sleep:缓存加载器的每次迭代工作之后的睡眠时长;
          loader_threashold:缓存加载器的最大睡眠时长;
    proxy_cache_valid [ code ... ] time:用于为不同的响应设定不同时长的有效缓存时长,例如: 
          proxy_cache_valid 200  302  10m;
    proxy_cache_methods [GET HEAD POST]:为哪些请求方法启用缓存功能;
    proxy_cache_bypass string:设定在哪种情形下,nginx将不从缓存中取数据。
示例:
# vim /etc/nginx/nginx.conf
http {
    include       mime.types;
    default_type  application/octet-stream;
    proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
    server {
        listen 80;
        server_name node1;
        add_header X-Via $server_addr;
        location / {
                root /www/html/b;
                index index.html index.htm;
        proxy_pass http://192.168.9.11;
        proxy_set_header Host $host;
        proxy_cache STATIC;
        proxy_cache_valid 200 1d;
        proxy_cache_valid 301 302 10m;
        proxy_cache_valid any 1m;
        proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
        }
   } 
}   

[[email protected] nginx]# mkdir -pv /data/nginx/cache
[[email protected] nginx]# nginx -t
[[email protected] nginx]# service nginx reload

缓存前请求时间

缓存后请求时间

####主要文件太小,效果不是太明显,有强迫症的同学可以自己测试。
##此时可以查看缓存目录是否有文件生成
[[email protected] ~]# ll /data/nginx/cache/
drwx------ 3 nginx nginx 4096 Jan 13 14:32 1

(2)、负载均衡:Nginx可以利用自身的upstream模块实现,upstream模块的负载均衡算法主要有三种,轮调(round-robin)、ip哈希(ip_hash)和最少连接(least_conn)三种。
    upstream模块常用的指令有:
        ip_hash:基于客户端IP地址完成请求的分发,它可以保证来自于同一个客户端的请求始终被转发至同一个upstream服务器;
        keepalive:每个worker进程为发送到upstream服务器的连接所缓存的个数;
        least_conn:最少连接调度算法;
        server:定义一个upstream服务器的地址,还可包括一系列可选参数,如;
            weight:权重;
            max_fails:最大失败的连接次数,失败连接的超时时长由fail_timeout指定;
            fail_timeout:等待请求的目录服务器发送响应的时长;
            backup:用于fallback的目的,所有服务均故障时才启动此服务器;
            down:手动标记其不再处理任何请求;
示例:
# vim /etc/nginx/nginx.conf
http {
    upstream web {
        server 192.168.9.11:80 max_fails=3 fail_timeout=10s;
        server 192.168.9.13:80 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:8080 backup;
        }
    server {
        listen 80;
        server_name www.c.net;
        add_header X-Via $server_addr;
        location / {
                root /www/html/b;
                index index.html index.htm;
        proxy_pass http://web;
        }
   }
   server {
        listen 8080;
        server_name 127.0.0.1;
        location / {
                root /www/html/b;
                index index.html index.htm;
        }
   }
   
[[email protected] ~]# curl http://www.c.net
192.168.9.11
[[email protected] ~]# curl http://www.c.net
192.168.9.13 
##停掉上游两台服务器后:
[[email protected] ~]# curl http://www.c.net
Sorry

#####Nginx的基本功能基本完成

The end

有关Nginx的基本配置及一般用法就写到这里了,第一次写Nginx的博客,写的比较乱,比较杂,敬请谅解,有什么不对的地方,麻烦朋友们告诉我。以上为个人学习整理,如有错漏,大神勿喷。。。。。

时间: 2024-07-30 10:13:11

Nginx基本使用方法及各模块基本功能的相关文章

NGINX编译安装后添加新模块的方法

刚忙完研发又有新的需求过来,测试服务器的nginx需要有HttpUpstreamRequestHashModule和HttpStubStatusModule:擦!安装软件环境时怎么不说清楚:妹的,悲剧. 测试服务器崩溃的是不是我安装的软件,天啊.赶紧搞吧!!! 环境:centos 6.4 64位 编译安装nginx 1:查看nginx版本和安装时间带的具体参数  /usr/local/nginx/sbin/nginx  -V 2:下载相应的版本的nginx源码包[nginx-1.5.11.tar

nginx下后端realserver健康检测模块ngx_http_upstream_check_module

想用Nginx或者Tengine替代LVS,即能做七层的负载均衡,又能做监控状态检测,一旦发现后面的realserver挂了就自动剔除,恢复后自动加入服务池里,可以用Tengine的ngx_http_upstream_check_module模块.本文主要介绍在工作中,搭建遇到问题及处理方法,便以后查询. 首先,我们大多数站点都是nginx+tomcat这个比较常见模式,其实nginx本身也有自己的健康检测模块,本人觉得不好用,故使用ngx_http_upstream_check_module.

Nginx反向绑定域名方法和详细操作应用实例:Google和Gravatar

反向绑定域名,即将域名B绑定到域名A上,用户只要访问B就等同于进入A,内容都是由A提供,它有点像建立了一个A的镜像.什么时候要用到反向绑定域名?服务器集群和网站负载均衡时,把用户访问请求发送不同的服务器上. 关于反向绑定域名的方法部落之前也分享过好几次,本篇文章就来详细介绍一下Nginx反向绑定域名方法.之所以要用Nginx,主要在于Nginx在反向绑定域名有着天然的优势,并且功能强大,可以满足我们更多更高的应用需求. 平常我们都是用Nginx反向绑定域名来搞定无法绑定域名的空间,这次来分享一下

nginx(四)安装第三方模块

nginx文件非常小但是性能非常的高效,这方面完胜apache,nginx文件小的一个原因之一是nginx自带的功能相对较少,好在nginx允许第三方模块,第三方模块使得nginx越发的强大. 在安装模块方面,nginx显得没有apache安装模块方便,当然也没有php安装扩展方便.在原生的nginx,他不可以动态加载模块,所以当你安装第三方模块的时候需要覆盖nginx文件.接下来看看如何安装nginx第三模块吧. nginx第三方模块安装方法: ./configure --prefix=/你的

nginx源码安装、文件模块的修改、访问加密(自定义签名证书)及负载均衡+轮询

主机环境 redhat6.5 实验环境 服务端 ip172.25.29.1    nginx    服务端 ip 172.25.29.2  apache    服务端 ip 172.25.29.3  apache    测试端 ip 172.25.254.29 安装包       nginx-1.10.1.tar.gz nginx用作反向代理 服务端1 1.  安装nginx 1.解压及简单配置 [[email protected] mnt]# yum install gcc -y      #

nginx编译安装和未编译模块的添加

安装nginx Yum 安装 参考http://nginx.org/en/linux_packages.html 编译安装nginx 系统首先要安装gcc* 包以及一些依赖包 [[email protected] tool]# wget http://nginx.org/download/nginx-1.8.0.tar.gz [[email protected] tool]# tar xf nginx-1.8.0.tar.gz -C /usr/local/src/ [[email protect

升级nginx,查看已经安装的模块,并隐藏或者修改版本号

升级前,查看已经安装的版本以及模块 [[email protected] ~]# /opt/nginx/sbin/nginx -Vnginx version: nginx/0.5.34 built by gcc 3.4.6 20060404 (Red Hat 3.4.6-3)configure arguments: --prefix=/opt/nginx --sbin-path=/opt/nginx/sbin/nginx --conf-path=/opt/nginx/conf/nginx.con

Drupal Nginx伪静态设置方法

location ~ ^.*/files\/styles\/.*$ { access_log off; expires 45d; error_page 404 @drupal; } location @drupal { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } } # Drupal Rewrite location / { root /path/to/drupal; index index.php i

使用Nginx+uWSGI+Django方法部署Django程序(下)

在上一篇文章<五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(上)>中,阐述了如何只使用uWSGI来部署Django程序. 当然,单单只有uWSGI是不够的,在实际的部署环境中,Nginx是必不可少的工具. 在本篇文章中,我将一直延用“N步法”的风格来阐述如何将uWSGI与Nginx做连接来部署Django程序.并在最后,会较为完整的阐述本社区的部署方法. 本文大纲: 环境介绍 配置uWSGI 配置Nginx Nginx+uWSGI+Django的实现方式 一些建