一、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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
1、安装依赖包(CentOS 6.7)
[root@mail soft] # yum -y groupinstall "Development tools,Server platform development,Desktop platform development"
[root@mail soft] # yum -y install pcre-devel openssl-devel
 
2、编译安装Nginx
[root@mail soft] # tar xf nginx-1.8.0.tar.gz 
[root@mail soft] # cd nginx-1.8.0
[root@mail nginx-1.8.0] # groupadd -r nginx
[root@mail nginx-1.8.0] # useradd -g nginx -s /sbin/nologin -M nginx
[root@mail 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
  [root@mail nginx-1.8.0] # make && make install
      
  ##注意:编译后有些文件夹不会自动创建
 
[root@mail 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配置文件时语法着色,默认没有
[root@mail nginx-1.8.0] # cd 
[root@mail ~] # mkdir .vim
[root@mail ~] # cp -ra /u01/soft/nginx-1.8.0/contrib/vim/* .vim
[root@mail ~] # ls .vim
ftdetect  indent  syntax
 
编写启动脚本:
[root@mail ~] # 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
 
[root@mail ~] # chmod +x /etc/rc.d/init.d/nginx   #添加可执行权限
[root@mail ~] # chkconfig --add nginx   #添加到服务列表
[root@mail ~] # chkconfig nginx on      #设置开机自启动
 
[root@mail ~] # service nginx start   #启动nginx
Starting nginx:                                            [  OK  ]
[root@mail ~] # ss -tnl     #查看是否监听80端口
[root@mail ~] # 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                               *:* 
##查看页面
[root@mail ~] # curl http://localhost
< head >
Welcome to nginx!<</code> <code class="bash plain">/title</code> <code class="bash plain">></code> </div> <div class="line number164 index163 alt1"> <code class="bash plain"><style></code> </div> <div class="line number165 index164 alt2"> <code class="bash spaces">    </code> <code class="bash plain">body {</code> </div> <div class="line number166 index165 alt1"> <code class="bash spaces">        </code> <code class="bash plain">width: 35em;</code> </div> <div class="line number167 index166 alt2"> <code class="bash spaces">        </code> <code class="bash plain">margin: 0 auto;</code> </div> <div class="line number168 index167 alt1"> <code class="bash spaces">        </code> <code class="bash plain">font-family: Tahoma, Verdana, Arial, sans-serif;</code> </div> <div class="line number169 index168 alt2"> <code class="bash spaces">    </code> <code class="bash plain">}</code> </div> <div class="line number170 index169 alt1"> <code class="bash plain"><</code> <code class="bash plain">/style</code> <code class="bash plain">></code> </div> <div class="line number171 index170 alt2"> <code class="bash plain"><</code> <code class="bash plain">/head</code> <code class="bash plain">></code> </div> <div class="line number172 index171 alt1"> <code class="bash plain"><body></code> </div> <div class="line number173 index172 alt2"> <code class="bash plain"><h1>Welcome to nginx!<</code> <code class="bash plain">/h1</code> <code class="bash plain">></code> </div> <div class="line number174 index173 alt1"> <code class="bash plain"><p>If you see this page, the nginx web server is successfully installed and</code> </div> <div class="line number175 index174 alt2"> <code class="bash plain">working. Further configuration is required.<</code> <code class="bash plain">/p</code> <code class="bash plain">></code> </div> <div class="line number176 index175 alt1">   </div> <div class="line number177 index176 alt2"> <code class="bash plain"><p>For online documentation and support please refer to</code> </div> <div class="line number178 index177 alt1"> <code class="bash plain"><a href=</code> <code class="bash string">"http://nginx.org/"</code> <code class="bash plain">>nginx.org<</code> <code class="bash plain">/a</code> <code class="bash plain">>.<br/></code> </div> <div class="line number179 index178 alt2"> <code class="bash plain">Commercial support is available at</code> </div> <div class="line number180 index179 alt1"> <code class="bash plain"><a href=</code> <code class="bash string">"http://nginx.com/"</code> <code class="bash plain">>nginx.com<</code> <code class="bash plain">/a</code> <code class="bash plain">>.<</code> <code class="bash plain">/p</code> <code class="bash plain">></code> </div> <div class="line number181 index180 alt2">   </div> <div class="line number182 index181 alt1"> <code class="bash plain"><p><em>Thank you </code> <code class="bash keyword">for</code>  <code class="bash plain">using nginx.<</code> <code class="bash plain">/em</code> <code class="bash plain">><</code> <code class="bash plain">/p</code> <code class="bash plain">></code> </div> <div class="line number183 index182 alt2"> <code class="bash plain"><</code> <code class="bash plain">/body</code> <code class="bash plain">></code> </div> <div class="line number184 index183 alt1"> <code class="bash plain"><</code> <code class="bash plain">/html</code> <code class="bash plain">></code> </div> <div class="line number185 index184 alt2"> <code class="bash comments">#######################编译安装已经完成。</code> </div> <div class="line number186 index185 alt1">   </div> <div class="line number187 index186 alt2"> <code class="bash plain">配置文件介绍</code> </div> <div class="line number188 index187 alt1"> <code class="bash spaces">  </code> <code class="bash plain">主要有两部分:分别是</code> </div> <div class="line number189 index188 alt2"> <code class="bash spaces">    </code> <code class="bash plain">main:主体部分</code> </div> <div class="line number190 index189 alt1"> <code class="bash spaces">    </code> <code class="bash plain">http{}:虚拟主机配置部分</code> </div> <div class="line number191 index190 alt2"> <code class="bash spaces">    </code>  </div> <div class="line number192 index191 alt1"> <code class="bash spaces">   </code> <code class="bash plain">配置指令主要以分号结尾;配置语法:directive value1 [value2 ....]</code> </div> <div class="line number193 index192 alt2"> <code class="bash spaces">   </code> <code class="bash plain">支持使用的变量</code> </div> <div class="line number194 index193 alt1"> <code class="bash spaces">       </code> <code class="bash plain">模块内置的变量</code> </div> <div class="line number195 index194 alt2"> <code class="bash spaces">       </code> <code class="bash plain">自定义变量:</code> <code class="bash functions">set</code>  <code class="bash plain">var_name value</code> </div> <div class="line number196 index195 alt1"> <code class="bash spaces">   </code>  </div> <div class="line number197 index196 alt2"> <code class="bash spaces">   </code> <code class="bash plain">主配置段的指令类别:</code> </div> <div class="line number198 index197 alt1"> <code class="bash spaces">  </code> <code class="bash plain">用于调试和定位问题:</code> </div> <div class="line number199 index198 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(1)daemon [on|off]:  是否以守护进程的方式启动nginx;</code> </div> <div class="line number200 index199 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(2)master_press [on|off]:  是否以master</code> <code class="bash plain">/worker</code> <code class="bash plain">模型来运行nginx;</code> </div> <div class="line number201 index200 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(3)error_log </code> <code class="bash plain">/path/to/error_loglevel</code> <code class="bash plain">:  指明错误日志文件级别,处于调试目的,可以使用debug级别,但次级别只有在编译nginx时使用了--with-debug选项才有效 ;</code> </div> <div class="line number202 index201 alt1"> <code class="bash spaces">       </code>  </div> <div class="line number203 index202 alt2"> <code class="bash spaces">  </code> <code class="bash plain">正常运行必备的配置:</code> </div> <div class="line number204 index203 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(1)user USERNAME [GROUPNAME]:指定运行worker的用户和用户组;例如 user nginx nginx </code> </div> <div class="line number205 index204 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(2)pid </code> <code class="bash plain">/path/to/nginx</code> <code class="bash plain">.pid : 指定pid文件</code> </div> <div class="line number206 index205 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(3)worker_rlimit_nofile </code> <code class="bash comments"># : 指定一个worker进程能够打开的最大文件句柄数</code> </div> <div class="line number207 index206 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(4)worker_rlimit_sigpending </code> <code class="bash comments"># : 指定每个用户能够发往worker信号的数量</code> </div> <div class="line number208 index207 alt1"> <code class="bash spaces">       </code>  </div> <div class="line number209 index208 alt2"> <code class="bash spaces">  </code> <code class="bash plain">优化性能相关的配置:</code> </div> <div class="line number210 index209 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(1)worker_processes </code> <code class="bash comments"># :worker进程的个数,通常是cpu核心数减1</code> </div> <div class="line number211 index210 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(2)worker_cpu_affinity cpuumask :绑定worker进程至指定的CPU上</code> </div> <div class="line number212 index211 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(3)timer-resolution t :时间解析度,在x86服务器上可以不用配置</code> </div> <div class="line number213 index212 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(4)worker_priority NICE :调整</code> <code class="bash functions">nice</code> <code class="bash plain">值(-20,19);</code> <code class="bash functions">nice</code> <code class="bash plain">值越大,越优先分配cpu</code> </div> <div class="line number214 index213 alt1"> <code class="bash spaces">       </code>  </div> <div class="line number215 index214 alt2"> <code class="bash spaces">  </code> <code class="bash plain">事件相关的配置;</code> </div> <div class="line number216 index215 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(1)accept_mutex [on|off] :内部调动用户请求至各worker时的负载均衡锁;启用时表示能够让多个worker轮流的、序列化的响应请求</code> </div> <div class="line number217 index216 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(2)lock_file </code> <code class="bash plain">/path/to/lock_file</code>  <code class="bash plain">:指定锁文件</code> </div> <div class="line number218 index217 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(3)accept_mutex_delay </code> <code class="bash comments">#ms: 取得负载均衡锁的时间</code> </div> <div class="line number219 index218 alt2"> <code class="bash spaces">   </code> <code class="bash plain">(4)use [epoll|poll|</code> <code class="bash functions">select</code> <code class="bash plain">|rgsig]:定义使用的事件模型,建议让nginx自动选择</code> </div> <div class="line number220 index219 alt1"> <code class="bash spaces">   </code> <code class="bash plain">(5)worker_connections </code> <code class="bash comments">#:每个worker进程所能够响应的最大并发请求数</code> </div></td> </tr> </tbody> </table> <p>五、Nginx的一些基本功能实现</p> <table style="width:716px;"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div></td> <td class="code"> <div class="line number1 index0 alt2"> <code class="bash plain">1、基于用户认证:</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">(1)、修改配置文件</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">server {</code> </div> <div class="line number4 index3 alt1"> <code class="bash spaces">        </code> <code class="bash plain">listen       80;</code> </div> <div class="line number5 index4 alt2"> <code class="bash spaces">        </code> <code class="bash plain">server_name  localhost;</code> </div> <div class="line number6 index5 alt1">   </div> <div class="line number7 index6 alt2"> <code class="bash spaces">        </code> <code class="bash comments">#charset koi8-r;</code> </div> <div class="line number8 index7 alt1">   </div> <div class="line number9 index8 alt2"> <code class="bash spaces">        </code> <code class="bash comments">#access_log  logs/host.access.log  main;</code> </div> <div class="line number10 index9 alt1">   </div> <div class="line number11 index10 alt2"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number12 index11 alt1"> <code class="bash spaces">            </code> <code class="bash plain">root   html;</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">            </code> <code class="bash plain">index  index.html index.htm;</code> </div> <div class="line number14 index13 alt1"> <code class="bash spaces">        </code> <code class="bash plain">auth_basic </code> <code class="bash string">"www.bjwf125.com"</code> <code class="bash plain">;</code> </div> <div class="line number15 index14 alt2"> <code class="bash spaces">        </code> <code class="bash plain">auth_basic_user_file </code> <code class="bash plain">/www/html/</code> <code class="bash plain">.</code> <code class="bash functions">passwd</code> <code class="bash plain">;</code> </div> <div class="line number16 index15 alt1"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number17 index16 alt2"> <code class="bash spaces"> </code> <code class="bash plain">}</code> </div> <div class="line number18 index17 alt1"> <code class="bash plain">(2)、创建文档根目录以及使用httpd-tools中的htpasswd工具创建用户</code> </div> <div class="line number19 index18 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># mkdir -pv /www/html</code> </div> <div class="line number20 index19 alt1"> <code class="bash functions">mkdir</code> <code class="bash plain">: created directory `</code> <code class="bash plain">/www</code> <code class="bash plain">'</code> </div> <div class="line number21 index20 alt2"> <code class="bash functions">mkdir</code> <code class="bash plain">: created directory `</code> <code class="bash plain">/www/html</code> <code class="bash plain">'</code> </div> <div class="line number22 index21 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># echo "Welcome to bjwf125" > /www/html/index.html</code> </div> <div class="line number23 index22 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># yum -y install httpd-tools</code> </div> <div class="line number24 index23 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># htpasswd -c -m /www/html/.passwd centos    #创建centos用户</code> </div> <div class="line number25 index24 alt2"> <code class="bash plain">New password:                                    </code> <code class="bash comments">#输入密码</code> </div> <div class="line number26 index25 alt1"> <code class="bash plain">Re-</code> <code class="bash functions">type</code>  <code class="bash plain">new password:                            </code> <code class="bash comments">#再次输入</code> </div> <div class="line number27 index26 alt2"> <code class="bash plain">Adding password </code> <code class="bash keyword">for</code>  <code class="bash plain">user centos</code> </div> <div class="line number28 index27 alt1"> <code class="bash plain">(3)、重新载入配置文件</code> </div> <div class="line number29 index28 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># nginx -t    #检查Nginx语法</code> </div> <div class="line number30 index29 alt1"> <code class="bash plain">nginx: the configuration </code> <code class="bash functions">file</code>  <code class="bash plain">/etc/nginx/nginx</code> <code class="bash plain">.conf syntax is ok</code> </div> <div class="line number31 index30 alt2"> <code class="bash plain">nginx: configuration </code> <code class="bash functions">file</code>  <code class="bash plain">/etc/nginx/nginx</code> <code class="bash plain">.conf </code> <code class="bash functions">test</code>  <code class="bash plain">is successful</code> </div> <div class="line number32 index31 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># service nginx reload     #重新载入</code> </div></td> </tr> </tbody> </table> <p><a href="http://img.e-com-net.com/image/info3/32acc215b44245e5a8a20dc797b58fda.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info3/32acc215b44245e5a8a20dc797b58fda.jpg" title="QQ图片20160113094920.png" alt="Nginx基本使用方法及各模块基本功能_第1张图片" width="650" height="470" style="border:1px solid black;"></a></p> <table> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div> <div class="line number33 index32 alt2"> 33 </div> <div class="line number34 index33 alt1"> 34 </div> <div class="line number35 index34 alt2"> 35 </div> <div class="line number36 index35 alt1"> 36 </div> <div class="line number37 index36 alt2"> 37 </div> <div class="line number38 index37 alt1"> 38 </div> <div class="line number39 index38 alt2"> 39 </div> <div class="line number40 index39 alt1"> 40 </div> <div class="line number41 index40 alt2"> 41 </div> <div class="line number42 index41 alt1"> 42 </div> <div class="line number43 index42 alt2"> 43 </div></td> <td class="code"> <div class="line number1 index0 alt2"> <code class="bash plain">2、基于IP认证</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">server {</code> </div> <div class="line number3 index2 alt2"> <code class="bash spaces">        </code> <code class="bash plain">listen       80;</code> </div> <div class="line number4 index3 alt1"> <code class="bash spaces">        </code> <code class="bash plain">server_name  localhost;</code> </div> <div class="line number5 index4 alt2">   </div> <div class="line number6 index5 alt1"> <code class="bash spaces">        </code> <code class="bash comments">#charset koi8-r;</code> </div> <div class="line number7 index6 alt2">   </div> <div class="line number8 index7 alt1"> <code class="bash spaces">        </code> <code class="bash comments">#access_log  logs/host.access.log  main;</code> </div> <div class="line number9 index8 alt2">   </div> <div class="line number10 index9 alt1"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number11 index10 alt2"> <code class="bash spaces">            </code> <code class="bash plain">root   html;</code> </div> <div class="line number12 index11 alt1"> <code class="bash spaces">            </code> <code class="bash plain">index  index.html index.htm;</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">        </code> <code class="bash plain">deny 192.168.9.0</code> <code class="bash plain">/24</code> <code class="bash plain">;</code> </div> <div class="line number14 index13 alt1"> <code class="bash spaces">        </code> <code class="bash plain">allow all;</code> </div> <div class="line number15 index14 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number16 index15 alt1"> <code class="bash spaces"> </code> <code class="bash plain">}</code> </div> <div class="line number17 index16 alt2"> <code class="bash spaces"> </code> <code class="bash plain">3、基于</code> <code class="bash functions">gzip</code> <code class="bash plain">压缩</code> </div> <div class="line number18 index17 alt1"> <code class="bash spaces"> </code> <code class="bash plain">server {</code> </div> <div class="line number19 index18 alt2"> <code class="bash spaces">        </code> <code class="bash plain">listen       80;</code> </div> <div class="line number20 index19 alt1"> <code class="bash spaces">        </code> <code class="bash plain">server_name  localhost;</code> </div> <div class="line number21 index20 alt2">   </div> <div class="line number22 index21 alt1"> <code class="bash spaces">        </code> <code class="bash comments">#charset koi8-r;</code> </div> <div class="line number23 index22 alt2">   </div> <div class="line number24 index23 alt1"> <code class="bash spaces">        </code> <code class="bash comments">#access_log  logs/host.access.log  main;</code> </div> <div class="line number25 index24 alt2">   </div> <div class="line number26 index25 alt1"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number27 index26 alt2"> <code class="bash spaces">            </code> <code class="bash plain">root   </code> <code class="bash plain">/www/html</code> <code class="bash plain">;</code> </div> <div class="line number28 index27 alt1"> <code class="bash spaces">            </code> <code class="bash plain">index  index.html index.htm;</code> </div> <div class="line number29 index28 alt2"> <code class="bash spaces">        </code> <code class="bash functions">gzip</code>  <code class="bash plain">on;</code> </div> <div class="line number30 index29 alt1"> <code class="bash spaces">        </code> <code class="bash plain">gzip_http_version 1.0;</code> </div> <div class="line number31 index30 alt2"> <code class="bash spaces">        </code> <code class="bash plain">gzip_min_length 1000;</code> </div> <div class="line number32 index31 alt1"> <code class="bash spaces">        </code> <code class="bash plain">gzip_proxied expired no-cache no-store private auth;</code> </div> <div class="line number33 index32 alt2"> <code class="bash spaces">        </code> <code class="bash plain">gzip_types text</code> <code class="bash plain">/plain</code>  <code class="bash plain">application</code> <code class="bash plain">/xml</code>  <code class="bash plain">text</code> <code class="bash plain">/css</code>  <code class="bash plain">application</code> <code class="bash plain">/x-javascript</code>  <code class="bash plain">text</code> <code class="bash plain">/xml</code> </div> <div class="line number34 index33 alt1"> <code class="bash spaces">             </code> <code class="bash plain">application</code> <code class="bash plain">/xml</code> <code class="bash plain">+rss text</code> <code class="bash plain">/javascript</code>  <code class="bash plain">application</code> <code class="bash plain">/javascript</code>  <code class="bash plain">application</code> <code class="bash plain">/json</code> <code class="bash plain">;</code> </div> <div class="line number35 index34 alt2"> <code class="bash spaces">        </code> <code class="bash plain">gzip_disable msie6 safari;</code> </div> <div class="line number36 index35 alt1">   </div> <div class="line number37 index36 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number38 index37 alt1"> <code class="bash spaces"> </code> <code class="bash plain">}</code> </div> <div class="line number39 index38 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># nginx -t</code> </div> <div class="line number40 index39 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># service nginx reload</code> </div> <div class="line number41 index40 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># cp /etc/rc.d/rc.sysinit /www/html/zip.html</code> </div> <div class="line number42 index41 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># ll /www/html/zip.html -h</code> </div> <div class="line number43 index42 alt2"> <code class="bash plain">-rwxr-xr-x 1 root root 20K Jan 13 10:01 </code> <code class="bash plain">/www/html/zip</code> <code class="bash plain">.html</code> </div></td> </tr> </tbody> </table> <p><a href="http://img.e-com-net.com/image/info3/88e3fcd7167a466d85f2f796bd7c58fa.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info3/88e3fcd7167a466d85f2f796bd7c58fa.jpg" title="QQ图片20160113101552.png" alt="Nginx基本使用方法及各模块基本功能_第2张图片" width="650" height="424" style="border:1px solid black;"></a></p> <table> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div></td> <td class="code"> <div class="line number1 index0 alt2"> <code class="bash plain">4、定制响应头部</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">server {</code> </div> <div class="line number3 index2 alt2"> <code class="bash spaces">        </code> <code class="bash plain">listen       80;</code> </div> <div class="line number4 index3 alt1"> <code class="bash spaces">        </code> <code class="bash plain">server_name  localhost;</code> </div> <div class="line number5 index4 alt2">   </div> <div class="line number6 index5 alt1"> <code class="bash spaces">        </code> <code class="bash comments">#charset koi8-r;</code> </div> <div class="line number7 index6 alt2">   </div> <div class="line number8 index7 alt1"> <code class="bash spaces">        </code> <code class="bash comments">#access_log  logs/host.access.log  main;</code> </div> <div class="line number9 index8 alt2">   </div> <div class="line number10 index9 alt1"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number11 index10 alt2"> <code class="bash spaces">            </code> <code class="bash plain">root   </code> <code class="bash plain">/www/html</code> <code class="bash plain">;</code> </div> <div class="line number12 index11 alt1"> <code class="bash spaces">            </code> <code class="bash plain">index  index.html index.htm;</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">        </code> <code class="bash plain">expires 24h;</code> </div> <div class="line number14 index13 alt1"> <code class="bash spaces">        </code> <code class="bash plain">add_header bjwf125 mymail;</code> </div> <div class="line number15 index14 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">}</code> </div> <div class="line number17 index16 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># nginx -t</code> </div> <div class="line number18 index17 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># service nginx reload</code> </div></td> </tr> </tbody> </table> <p></p> <table> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div></td> <td class="code"> <div class="line number1 index0 alt2"> <code class="bash plain">5、URL重定向</code> </div> <div class="line number2 index1 alt1"> <code class="bash spaces">   </code> <code class="bash plain">语法格式:</code> </div> <div class="line number3 index2 alt2"> <code class="bash spaces">   </code> <code class="bash plain">rewrite grgex replacement [flages]</code> </div> <div class="line number4 index3 alt1"> <code class="bash spaces">   </code> <code class="bash plain">flages</code> </div> <div class="line number5 index4 alt2"> <code class="bash spaces">   </code> <code class="bash plain">last:一旦被当前规则匹配并重写后立即停止检查其他后续的rewrite的规则,而后通过重写后的规则重写发起请求;</code> </div> <div class="line number6 index5 alt1"> <code class="bash spaces">   </code> <code class="bash plain">bleak:一旦被当前规则匹配并重写后立即停止后续的其他rewrite的规则,而后由nginx进行后续操作;</code> </div> <div class="line number7 index6 alt2"> <code class="bash spaces">   </code> <code class="bash plain">redirect:返回302临时重定向</code> </div> <div class="line number8 index7 alt1"> <code class="bash spaces">   </code> <code class="bash plain">permanent:返回301永久重定向</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">例如:</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># vim /etc/nginx/nginx.conf</code> </div> <div class="line number11 index10 alt2"> <code class="bash spaces"> </code> <code class="bash plain">server {</code> </div> <div class="line number12 index11 alt1"> <code class="bash spaces">        </code> <code class="bash plain">listen       80;</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">        </code> <code class="bash plain">server_name  localhost;</code> </div> <div class="line number14 index13 alt1">   </div> <div class="line number15 index14 alt2"> <code class="bash spaces">        </code> <code class="bash comments">#charset koi8-r;</code> </div> <div class="line number16 index15 alt1">   </div> <div class="line number17 index16 alt2"> <code class="bash spaces">        </code> <code class="bash comments">#access_log  logs/host.access.log  main;</code> </div> <div class="line number18 index17 alt1">   </div> <div class="line number19 index18 alt2"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number20 index19 alt1"> <code class="bash spaces">            </code> <code class="bash plain">root   </code> <code class="bash plain">/www/html</code> <code class="bash plain">;</code> </div> <div class="line number21 index20 alt2"> <code class="bash spaces">            </code> <code class="bash plain">index  index.html index.htm;</code> </div> <div class="line number22 index21 alt1"> <code class="bash spaces">        </code> <code class="bash plain">rewrite ^</code> <code class="bash plain">/admin/</code> <code class="bash plain">(.*)$ </code> <code class="bash plain">/web/</code> <code class="bash plain">$1;</code> </div> <div class="line number23 index22 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number24 index23 alt1"> <code class="bash spaces">  </code> <code class="bash plain">}</code> </div> <div class="line number25 index24 alt2"> <code class="bash spaces">  </code>  </div> <div class="line number26 index25 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># mkdir -pv /www/html/{admin,web}</code> </div> <div class="line number27 index26 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># echo "mail.bjwf125.com" > /www/html/web/index.html</code> </div> <div class="line number28 index27 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># nginx -t</code> </div> <div class="line number29 index28 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># service nginx reload</code> </div></td> </tr> </tbody> </table> <p><a href="http://img.e-com-net.com/image/info3/73e2b539adcd473a8280afcf72a9e7f8.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info3/73e2b539adcd473a8280afcf72a9e7f8.jpg" title="QQ图片20160113103608.png" alt="Nginx基本使用方法及各模块基本功能_第3张图片" width="650" height="617" style="border:1px solid black;"></a></p> <table> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div> <div class="line number33 index32 alt2"> 33 </div> <div class="line number34 index33 alt1"> 34 </div> <div class="line number35 index34 alt2"> 35 </div> <div class="line number36 index35 alt1"> 36 </div> <div class="line number37 index36 alt2"> 37 </div> <div class="line number38 index37 alt1"> 38 </div> <div class="line number39 index38 alt2"> 39 </div> <div class="line number40 index39 alt1"> 40 </div> <div class="line number41 index40 alt2"> 41 </div> <div class="line number42 index41 alt1"> 42 </div> <div class="line number43 index42 alt2"> 43 </div> <div class="line number44 index43 alt1"> 44 </div> <div class="line number45 index44 alt2"> 45 </div> <div class="line number46 index45 alt1"> 46 </div> <div class="line number47 index46 alt2"> 47 </div> <div class="line number48 index47 alt1"> 48 </div> <div class="line number49 index48 alt2"> 49 </div> <div class="line number50 index49 alt1"> 50 </div> <div class="line number51 index50 alt2"> 51 </div> <div class="line number52 index51 alt1"> 52 </div> <div class="line number53 index52 alt2"> 53 </div> <div class="line number54 index53 alt1"> 54 </div> <div class="line number55 index54 alt2"> 55 </div> <div class="line number56 index55 alt1"> 56 </div> <div class="line number57 index56 alt2"> 57 </div> <div class="line number58 index57 alt1"> 58 </div> <div class="line number59 index58 alt2"> 59 </div> <div class="line number60 index59 alt1"> 60 </div> <div class="line number61 index60 alt2"> 61 </div> <div class="line number62 index61 alt1"> 62 </div> <div class="line number63 index62 alt2"> 63 </div> <div class="line number64 index63 alt1"> 64 </div> <div class="line number65 index64 alt2"> 65 </div> <div class="line number66 index65 alt1"> 66 </div> <div class="line number67 index66 alt2"> 67 </div> <div class="line number68 index67 alt1"> 68 </div> <div class="line number69 index68 alt2"> 69 </div> <div class="line number70 index69 alt1"> 70 </div></td> <td class="code"> <div class="line number1 index0 alt2"> <code class="bash plain">6、虚拟主机</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># vim /etc/nginx/nginx.conf</code> </div> <div class="line number3 index2 alt2"> <code class="bash comments">#注释掉http{}段中的预定义server{}段中的所有内容;</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">在文件末尾}前一行添加一条:</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">include conf.d</code> <code class="bash plain">/nginx-vhost</code> <code class="bash plain">.conf;</code> </div> <div class="line number6 index5 alt1"> <code class="bash comments">#方便后面定义,根据个人习惯而已,也可以直接在/etc/nginx/nginx.conf中配置</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># vim /etc/nginx/conf.d/nginx-vhost.conf </code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">server {</code> </div> <div class="line number9 index8 alt2"> <code class="bash spaces">   </code> <code class="bash plain">listen       80;</code> </div> <div class="line number10 index9 alt1"> <code class="bash spaces">   </code> <code class="bash plain">server_name  www.a.com;</code> </div> <div class="line number11 index10 alt2"> <code class="bash spaces">        </code>  </div> <div class="line number12 index11 alt1"> <code class="bash spaces">   </code> <code class="bash plain">location / {</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">        </code> <code class="bash plain">root    </code> <code class="bash plain">/www/html/a</code> <code class="bash plain">;</code> </div> <div class="line number14 index13 alt1"> <code class="bash spaces">        </code> <code class="bash plain">index   index.html index.htm;</code> </div> <div class="line number15 index14 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">}</code> </div> <div class="line number17 index16 alt2"> <code class="bash spaces"> </code>  </div> <div class="line number18 index17 alt1"> <code class="bash plain">server {</code> </div> <div class="line number19 index18 alt2"> <code class="bash spaces">   </code> <code class="bash plain">listen       80;</code> </div> <div class="line number20 index19 alt1"> <code class="bash spaces">   </code> <code class="bash plain">server_name  www.b.com;</code> </div> <div class="line number21 index20 alt2"> <code class="bash spaces">        </code>  </div> <div class="line number22 index21 alt1"> <code class="bash spaces">   </code> <code class="bash plain">location / {</code> </div> <div class="line number23 index22 alt2"> <code class="bash spaces">        </code> <code class="bash plain">root    </code> <code class="bash plain">/www/html/b</code> <code class="bash plain">;</code> </div> <div class="line number24 index23 alt1"> <code class="bash spaces">        </code> <code class="bash plain">index   index.html index.htm;</code> </div> <div class="line number25 index24 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number26 index25 alt1"> <code class="bash plain">}</code> </div> <div class="line number27 index26 alt2">   </div> <div class="line number28 index27 alt1"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># mkdir /www/html/{a,b} -pv</code> </div> <div class="line number29 index28 alt2"> <code class="bash functions">mkdir</code> <code class="bash plain">: created directory `</code> <code class="bash plain">/www/html/a</code> <code class="bash plain">'</code> </div> <div class="line number30 index29 alt1"> <code class="bash functions">mkdir</code> <code class="bash plain">: created directory `</code> <code class="bash plain">/www/html/b</code> <code class="bash plain">'</code> </div> <div class="line number31 index30 alt2"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># echo "www.a.com" > /www/html/a/index.html</code> </div> <div class="line number32 index31 alt1"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># echo "www.b.com" > /www/html/b/index.html</code> </div> <div class="line number33 index32 alt2"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># vim /etc/hosts</code> </div> <div class="line number34 index33 alt1"> <code class="bash plain">192.168.9.9     www.a.com</code> </div> <div class="line number35 index34 alt2"> <code class="bash plain">192.168.9.9     www.b.com</code> </div> <div class="line number36 index35 alt1"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># service nginx reload</code> </div> <div class="line number37 index36 alt2"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># curl http://www.a.com</code> </div> <div class="line number38 index37 alt1"> <code class="bash plain">www.a.com</code> </div> <div class="line number39 index38 alt2"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># curl http://www.b.com</code> </div> <div class="line number40 index39 alt1"> <code class="bash plain">www.b.com</code> </div> <div class="line number41 index40 alt2"> <code class="bash comments">###虚拟主机最简单的方式已经配置完成,但是虚拟主机里面还有很多参数。</code> </div> <div class="line number42 index41 alt1"> <code class="bash plain">7、防盗链</code> </div> <div class="line number43 index42 alt2"> <code class="bash plain">(1)、定义合规的引用</code> </div> <div class="line number44 index43 alt1"> <code class="bash spaces">        </code> <code class="bash plain">valid_referers none | blocked | server_names | string ...;</code> </div> <div class="line number45 index44 alt2"> <code class="bash spaces"> </code> <code class="bash plain">(2)、拒绝不合规的引用</code> </div> <div class="line number46 index45 alt1"> <code class="bash spaces">         </code> <code class="bash keyword">if</code>  <code class="bash plain">($invalid referer) {</code> </div> <div class="line number47 index46 alt2"> <code class="bash spaces">          </code> <code class="bash plain">rewrite ^/ http:</code> <code class="bash plain">//www</code> <code class="bash plain">.b.com</code> <code class="bash plain">/403</code> <code class="bash plain">.html;</code> </div> <div class="line number48 index47 alt1"> <code class="bash spaces">         </code> <code class="bash plain">}</code> </div> <div class="line number49 index48 alt2"> <code class="bash spaces">  </code> <code class="bash comments">##具体示例如下:</code> </div> <div class="line number50 index49 alt1"> <code class="bash spaces">  </code> <code class="bash plain">[root@mail conf.d]</code> <code class="bash comments"># vim nginx-vhost.conf</code> </div> <div class="line number51 index50 alt2"> <code class="bash spaces">   </code> <code class="bash plain">server {</code> </div> <div class="line number52 index51 alt1"> <code class="bash spaces">   </code> <code class="bash plain">listen       80;</code> </div> <div class="line number53 index52 alt2"> <code class="bash spaces">   </code> <code class="bash plain">server_name  www.b.com;</code> </div> <div class="line number54 index53 alt1"> <code class="bash spaces">        </code>  </div> <div class="line number55 index54 alt2"> <code class="bash spaces">   </code> <code class="bash plain">location / {</code> </div> <div class="line number56 index55 alt1"> <code class="bash spaces">        </code> <code class="bash plain">root    </code> <code class="bash plain">/www/html/b</code> <code class="bash plain">;</code> </div> <div class="line number57 index56 alt2"> <code class="bash spaces">        </code> <code class="bash plain">index   index.html index.htm;</code> </div> <div class="line number58 index57 alt1"> <code class="bash spaces">        </code> <code class="bash plain">valid_referers none blocked www.b.com *.b.com;</code> </div> <div class="line number59 index58 alt2"> <code class="bash spaces">        </code> <code class="bash keyword">if</code>  <code class="bash plain">($invalid_referer) {</code> </div> <div class="line number60 index59 alt1"> <code class="bash spaces">        </code> <code class="bash plain">rewrite ^/ http:</code> <code class="bash plain">//www</code> <code class="bash plain">.b.com</code> <code class="bash plain">/403</code> <code class="bash plain">.html;</code> </div> <div class="line number61 index60 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number62 index61 alt1"> <code class="bash spaces">      </code> <code class="bash plain">}</code> </div> <div class="line number63 index62 alt2"> <code class="bash spaces">   </code> <code class="bash plain">} </code> </div> <div class="line number64 index63 alt1"> <code class="bash spaces">   </code>  </div> <div class="line number65 index64 alt2"> <code class="bash spaces">   </code> <code class="bash plain">[root@mail conf.d]</code> <code class="bash comments"># vim /www/html/a/index.html</code> </div> <div class="line number66 index65 alt1"> <code class="bash spaces">   </code> <code class="bash plain">www.a.com</code> </div> <div class="line number67 index66 alt2"> <code class="bash spaces">   </code> <code class="bash plain"><img src=</code> <code class="bash string">"http://www.b.com/p_w_picpaths/1.jpg"</code> <code class="bash plain">>   </code> <code class="bash comments">#在a.com中引用</code> </div> <div class="line number68 index67 alt1"> <code class="bash spaces">    </code> <code class="bash plain">[root@mail conf.d]</code> <code class="bash comments"># vim /www/html/b/index.html</code> </div> <div class="line number69 index68 alt2"> <code class="bash spaces">   </code> <code class="bash plain">www.b.com</code> </div> <div class="line number70 index69 alt1"> <code class="bash spaces">   </code> <code class="bash plain"><img src=</code> <code class="bash string">"http://www.b.com/p_w_picpaths/1.jpg"</code> <code class="bash plain">>   </code> <code class="bash comments">#b.com自己引用</code> </div></td> </tr> </tbody> </table> <p>测试结果:</p> <p><a href="http://img.e-com-net.com/image/info3/6fc762522312486e8a53ef6d1886c911.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info3/6fc762522312486e8a53ef6d1886c911.jpg" title="222.png" alt="Nginx基本使用方法及各模块基本功能_第4张图片" width="650" height="420" style="border:1px solid black;"></a><a href="http://img.e-com-net.com/image/info3/4cf9115c4477498bafff10079675eca7.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info3/4cf9115c4477498bafff10079675eca7.jpg" title="111.png" alt="Nginx基本使用方法及各模块基本功能_第5张图片" width="650" height="529" style="border:1px solid black;"></a></p> <table style="width:716px;"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div> <div class="line number33 index32 alt2"> 33 </div> <div class="line number34 index33 alt1"> 34 </div> <div class="line number35 index34 alt2"> 35 </div> <div class="line number36 index35 alt1"> 36 </div> <div class="line number37 index36 alt2"> 37 </div> <div class="line number38 index37 alt1"> 38 </div> <div class="line number39 index38 alt2"> 39 </div> <div class="line number40 index39 alt1"> 40 </div> <div class="line number41 index40 alt2"> 41 </div> <div class="line number42 index41 alt1"> 42 </div> <div class="line number43 index42 alt2"> 43 </div> <div class="line number44 index43 alt1"> 44 </div> <div class="line number45 index44 alt2"> 45 </div> <div class="line number46 index45 alt1"> 46 </div> <div class="line number47 index46 alt2"> 47 </div> <div class="line number48 index47 alt1"> 48 </div> <div class="line number49 index48 alt2"> 49 </div> <div class="line number50 index49 alt1"> 50 </div> <div class="line number51 index50 alt2"> 51 </div> <div class="line number52 index51 alt1"> 52 </div> <div class="line number53 index52 alt2"> 53 </div> <div class="line number54 index53 alt1"> 54 </div> <div class="line number55 index54 alt2"> 55 </div> <div class="line number56 index55 alt1"> 56 </div> <div class="line number57 index56 alt2"> 57 </div> <div class="line number58 index57 alt1"> 58 </div> <div class="line number59 index58 alt2"> 59 </div> <div class="line number60 index59 alt1"> 60 </div> <div class="line number61 index60 alt2"> 61 </div> <div class="line number62 index61 alt1"> 62 </div> <div class="line number63 index62 alt2"> 63 </div> <div class="line number64 index63 alt1"> 64 </div> <div class="line number65 index64 alt2"> 65 </div> <div class="line number66 index65 alt1"> 66 </div></td> <td class="code"> <div class="line number1 index0 alt2"> <code class="bash plain">8、Nginx的反向代理</code> </div> <div class="line number2 index1 alt1"> <code class="bash spaces">   </code> <code class="bash plain">Nginx可以通过proxy模块实现反向代理功能,在作为web反向代理服务器时,Nginx复制接收客户端请求,并能够根据URL、客户端参数或者其它的处理逻辑将用户请求调度至上游服务器上(upstream server)。</code> </div> <div class="line number3 index2 alt2"> <code class="bash spaces">   </code> <code class="bash plain">Nginx在实现反向代理功能时最重要的指令为proxy_pass,它能够将location中定义的某URI代理至指定的上游服务器(组)上。如下面的示例中,location的URI将被替换为上游服务器上的newURI。</code> </div> <div class="line number4 index3 alt1"> <code class="bash comments">### 例如:</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">[root@mail conf.d]</code> <code class="bash comments"># vim nginx-vhost.conf </code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">server {</code> </div> <div class="line number7 index6 alt2"> <code class="bash spaces">   </code> <code class="bash plain">listen       80;</code> </div> <div class="line number8 index7 alt1"> <code class="bash spaces">   </code> <code class="bash plain">server_name  www.a.com;</code> </div> <div class="line number9 index8 alt2"> <code class="bash spaces">   </code> <code class="bash plain">add_header X-Via $server_addr;</code> </div> <div class="line number10 index9 alt1">   </div> <div class="line number11 index10 alt2"> <code class="bash spaces">   </code> <code class="bash plain">location / {</code> </div> <div class="line number12 index11 alt1"> <code class="bash spaces">        </code> <code class="bash plain">root    </code> <code class="bash plain">/www/html/a</code> <code class="bash plain">;</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">        </code> <code class="bash plain">index   index.html index.htm;</code> </div> <div class="line number14 index13 alt1"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number15 index14 alt2"> <code class="bash spaces">   </code> <code class="bash plain">location = </code> <code class="bash plain">/node2</code>  <code class="bash plain">{</code> </div> <div class="line number16 index15 alt1"> <code class="bash spaces">        </code> <code class="bash plain">proxy_pass http:</code> <code class="bash plain">//192</code> <code class="bash plain">.168.9.11/;</code> </div> <div class="line number17 index16 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number18 index17 alt1"> <code class="bash plain">}</code> </div> <div class="line number19 index18 alt2"> <code class="bash comments">##上游服务器必须要配置相应服务及页面</code> </div> <div class="line number20 index19 alt1"> <code class="bash plain">[root@mail conf.d]</code> <code class="bash comments"># service nginx reload</code> </div> <div class="line number21 index20 alt2"> <code class="bash plain">[root@mail conf.d]</code> <code class="bash comments"># curl  www.a.com</code> </div> <div class="line number22 index21 alt1"> <code class="bash plain"><img src=</code> <code class="bash string">"http://www.b.net/p_w_picpaths/1.jpg"</code> <code class="bash plain">> </code> </div> <div class="line number23 index22 alt2"> <code class="bash plain">[root@mail conf.d]</code> <code class="bash comments"># curl http://www.a.com/node1</code> </div> <div class="line number24 index23 alt1"> <code class="bash plain">node1.bjwf125.com</code> </div> <div class="line number25 index24 alt2">   </div> <div class="line number26 index25 alt1">   </div> <div class="line number27 index26 alt2"> <code class="bash plain">(1)、缓存:Nginx作为反向代理时,能够将上游服务器的响应缓存至本地,并在后续的客户端请求同样的内容时直接从本地构造响应报文。具体参数如下:</code> </div> <div class="line number28 index27 alt1"> <code class="bash spaces">    </code> <code class="bash plain">proxy_cache zone|off:定义一个用于缓存的共享内存区域,其可被多个地方调用;</code> </div> <div class="line number29 index28 alt2"> <code class="bash spaces">    </code> <code class="bash plain">proxy_cache_path:定义一个保存缓存响应报文的目录,及一个保存缓存对象的键及响应元数据的共享内存区域(keys_zone=name:size),其可选参数有:</code> </div> <div class="line number30 index29 alt1"> <code class="bash spaces">          </code> <code class="bash plain">levels:每级子目录名称的长度,有效值为1或2,每级之间使用冒号分隔,最多为3级;</code> </div> <div class="line number31 index30 alt2"> <code class="bash spaces">          </code> <code class="bash plain">inactive:非活动缓存项从缓存中剔除之前的最大缓存时长;</code> </div> <div class="line number32 index31 alt1"> <code class="bash spaces">          </code> <code class="bash plain">max_size:缓存空间大小的上限,当需要缓存的对象超出此空间限定时,缓存管理器将基于LRU算法对其进行清理;</code> </div> <div class="line number33 index32 alt2"> <code class="bash spaces">          </code> <code class="bash plain">loader_files:缓存加载器(cache_loader)的每次工作过程使用为多少个文件加载元数据;</code> </div> <div class="line number34 index33 alt1"> <code class="bash spaces">          </code> <code class="bash plain">loader_sleep:缓存加载器的每次迭代工作之后的睡眠时长;</code> </div> <div class="line number35 index34 alt2"> <code class="bash spaces">          </code> <code class="bash plain">loader_threashold:缓存加载器的最大睡眠时长;</code> </div> <div class="line number36 index35 alt1"> <code class="bash spaces">    </code> <code class="bash plain">proxy_cache_valid [ code ... ] </code> <code class="bash functions">time</code> <code class="bash plain">:用于为不同的响应设定不同时长的有效缓存时长,例如: </code> </div> <div class="line number37 index36 alt2"> <code class="bash spaces">          </code> <code class="bash plain">proxy_cache_valid 200  302  10m;</code> </div> <div class="line number38 index37 alt1"> <code class="bash spaces">    </code> <code class="bash plain">proxy_cache_methods [GET HEAD POST]:为哪些请求方法启用缓存功能;</code> </div> <div class="line number39 index38 alt2"> <code class="bash spaces">    </code> <code class="bash plain">proxy_cache_bypass string:设定在哪种情形下,nginx将不从缓存中取数据。</code> </div> <div class="line number40 index39 alt1"> <code class="bash plain">示例:</code> </div> <div class="line number41 index40 alt2"> <code class="bash comments"># vim /etc/nginx/nginx.conf</code> </div> <div class="line number42 index41 alt1"> <code class="bash plain">http {</code> </div> <div class="line number43 index42 alt2"> <code class="bash spaces">    </code> <code class="bash plain">include       mime.types;</code> </div> <div class="line number44 index43 alt1"> <code class="bash spaces">    </code> <code class="bash plain">default_type  application</code> <code class="bash plain">/octet-stream</code> <code class="bash plain">;</code> </div> <div class="line number45 index44 alt2"> <code class="bash spaces">    </code> <code class="bash plain">proxy_cache_path </code> <code class="bash plain">/data/nginx/cache</code>  <code class="bash plain">levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;</code> </div> <div class="line number46 index45 alt1"> <code class="bash spaces">    </code> <code class="bash plain">server {</code> </div> <div class="line number47 index46 alt2"> <code class="bash spaces">        </code> <code class="bash plain">listen 80;</code> </div> <div class="line number48 index47 alt1"> <code class="bash spaces">        </code> <code class="bash plain">server_name node1;</code> </div> <div class="line number49 index48 alt2"> <code class="bash spaces">        </code> <code class="bash plain">add_header X-Via $server_addr;</code> </div> <div class="line number50 index49 alt1"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number51 index50 alt2"> <code class="bash spaces">                </code> <code class="bash plain">root </code> <code class="bash plain">/www/html/b</code> <code class="bash plain">;</code> </div> <div class="line number52 index51 alt1"> <code class="bash spaces">                </code> <code class="bash plain">index index.html index.htm;</code> </div> <div class="line number53 index52 alt2"> <code class="bash spaces">        </code> <code class="bash plain">proxy_pass http:</code> <code class="bash plain">//192</code> <code class="bash plain">.168.9.11;</code> </div> <div class="line number54 index53 alt1"> <code class="bash spaces">        </code> <code class="bash plain">proxy_set_header Host $host;</code> </div> <div class="line number55 index54 alt2"> <code class="bash spaces">        </code> <code class="bash plain">proxy_cache STATIC;</code> </div> <div class="line number56 index55 alt1"> <code class="bash spaces">        </code> <code class="bash plain">proxy_cache_valid 200 1d;</code> </div> <div class="line number57 index56 alt2"> <code class="bash spaces">        </code> <code class="bash plain">proxy_cache_valid 301 302 10m;</code> </div> <div class="line number58 index57 alt1"> <code class="bash spaces">        </code> <code class="bash plain">proxy_cache_valid any 1m;</code> </div> <div class="line number59 index58 alt2"> <code class="bash spaces">        </code> <code class="bash plain">proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;</code> </div> <div class="line number60 index59 alt1"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number61 index60 alt2"> <code class="bash spaces">   </code> <code class="bash plain">} </code> </div> <div class="line number62 index61 alt1"> <code class="bash plain">}   </code> </div> <div class="line number63 index62 alt2">   </div> <div class="line number64 index63 alt1"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># mkdir -pv /data/nginx/cache</code> </div> <div class="line number65 index64 alt2"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># nginx -t</code> </div> <div class="line number66 index65 alt1"> <code class="bash plain">[root@mail nginx]</code> <code class="bash comments"># service nginx reload</code> </div></td> </tr> </tbody> </table> <p><br></p> <p>缓存前请求时间</p> <p><br></p> <p><a href="http://img.e-com-net.com/image/info3/2d9ef60131c44a519d0a7f5489ed756b.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info3/2d9ef60131c44a519d0a7f5489ed756b.jpg" title="1.png" alt="Nginx基本使用方法及各模块基本功能_第6张图片" width="650" height="617" style="border:1px solid black;"></a></p> <p><br></p> <p>缓存后请求时间</p> <p><br></p> <p><a href="http://img.e-com-net.com/image/info3/34b7399861e54ed2b74e4d9d2b910fb6.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info3/34b7399861e54ed2b74e4d9d2b910fb6.jpg" title="2.png" alt="Nginx基本使用方法及各模块基本功能_第7张图片" width="650" height="617" style="border:1px solid black;"></a></p> <table> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div> <div class="line number33 index32 alt2"> 33 </div> <div class="line number34 index33 alt1"> 34 </div> <div class="line number35 index34 alt2"> 35 </div> <div class="line number36 index35 alt1"> 36 </div> <div class="line number37 index36 alt2"> 37 </div> <div class="line number38 index37 alt1"> 38 </div> <div class="line number39 index38 alt2"> 39 </div> <div class="line number40 index39 alt1"> 40 </div> <div class="line number41 index40 alt2"> 41 </div> <div class="line number42 index41 alt1"> 42 </div> <div class="line number43 index42 alt2"> 43 </div> <div class="line number44 index43 alt1"> 44 </div> <div class="line number45 index44 alt2"> 45 </div> <div class="line number46 index45 alt1"> 46 </div> <div class="line number47 index46 alt2"> 47 </div> <div class="line number48 index47 alt1"> 48 </div> <div class="line number49 index48 alt2"> 49 </div> <div class="line number50 index49 alt1"> 50 </div> <div class="line number51 index50 alt2"> 51 </div> <div class="line number52 index51 alt1"> 52 </div></td> <td class="code"> <div class="line number1 index0 alt2"> <code class="bash comments">####主要文件太小,效果不是太明显,有强迫症的同学可以自己测试。</code> </div> <div class="line number2 index1 alt1"> <code class="bash comments">##此时可以查看缓存目录是否有文件生成</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># ll /data/nginx/cache/</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">drwx------ 3 nginx nginx 4096 Jan 13 14:32 1</code> </div> <div class="line number5 index4 alt2">   </div> <div class="line number6 index5 alt1"> <code class="bash plain">(2)、负载均衡:Nginx可以利用自身的upstream模块实现,upstream模块的负载均衡算法主要有三种,轮调(round-robin)、ip哈希(ip_hash)和最少连接(least_conn)三种。</code> </div> <div class="line number7 index6 alt2"> <code class="bash spaces">    </code> <code class="bash plain">upstream模块常用的指令有:</code> </div> <div class="line number8 index7 alt1"> <code class="bash spaces">        </code> <code class="bash plain">ip_hash:基于客户端IP地址完成请求的分发,它可以保证来自于同一个客户端的请求始终被转发至同一个upstream服务器;</code> </div> <div class="line number9 index8 alt2"> <code class="bash spaces">        </code> <code class="bash plain">keepalive:每个worker进程为发送到upstream服务器的连接所缓存的个数;</code> </div> <div class="line number10 index9 alt1"> <code class="bash spaces">        </code> <code class="bash plain">least_conn:最少连接调度算法;</code> </div> <div class="line number11 index10 alt2"> <code class="bash spaces">        </code> <code class="bash plain">server:定义一个upstream服务器的地址,还可包括一系列可选参数,如;</code> </div> <div class="line number12 index11 alt1"> <code class="bash spaces">            </code> <code class="bash plain">weight:权重;</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">            </code> <code class="bash plain">max_fails:最大失败的连接次数,失败连接的超时时长由fail_timeout指定;</code> </div> <div class="line number14 index13 alt1"> <code class="bash spaces">            </code> <code class="bash plain">fail_timeout:等待请求的目录服务器发送响应的时长;</code> </div> <div class="line number15 index14 alt2"> <code class="bash spaces">            </code> <code class="bash plain">backup:用于fallback的目的,所有服务均故障时才启动此服务器;</code> </div> <div class="line number16 index15 alt1"> <code class="bash spaces">            </code> <code class="bash plain">down:手动标记其不再处理任何请求;</code> </div> <div class="line number17 index16 alt2"> <code class="bash plain">示例:</code> </div> <div class="line number18 index17 alt1"> <code class="bash comments"># vim /etc/nginx/nginx.conf</code> </div> <div class="line number19 index18 alt2"> <code class="bash plain">http {</code> </div> <div class="line number20 index19 alt1"> <code class="bash spaces">    </code> <code class="bash plain">upstream web {</code> </div> <div class="line number21 index20 alt2"> <code class="bash spaces">        </code> <code class="bash plain">server 192.168.9.11:80 max_fails=3 fail_timeout=10s;</code> </div> <div class="line number22 index21 alt1"> <code class="bash spaces">        </code> <code class="bash plain">server 192.168.9.13:80 max_fails=3 fail_timeout=10s;</code> </div> <div class="line number23 index22 alt2"> <code class="bash spaces">        </code> <code class="bash plain">server 127.0.0.1:8080 backup;</code> </div> <div class="line number24 index23 alt1"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number25 index24 alt2"> <code class="bash spaces">    </code> <code class="bash plain">server {</code> </div> <div class="line number26 index25 alt1"> <code class="bash spaces">        </code> <code class="bash plain">listen 80;</code> </div> <div class="line number27 index26 alt2"> <code class="bash spaces">        </code> <code class="bash plain">server_name www.c.net;</code> </div> <div class="line number28 index27 alt1"> <code class="bash spaces">        </code> <code class="bash plain">add_header X-Via $server_addr;</code> </div> <div class="line number29 index28 alt2"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number30 index29 alt1"> <code class="bash spaces">                </code> <code class="bash plain">root </code> <code class="bash plain">/www/html/b</code> <code class="bash plain">;</code> </div> <div class="line number31 index30 alt2"> <code class="bash spaces">                </code> <code class="bash plain">index index.html index.htm;</code> </div> <div class="line number32 index31 alt1"> <code class="bash spaces">        </code> <code class="bash plain">proxy_pass http:</code> <code class="bash plain">//web</code> <code class="bash plain">;</code> </div> <div class="line number33 index32 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number34 index33 alt1"> <code class="bash spaces">   </code> <code class="bash plain">}</code> </div> <div class="line number35 index34 alt2"> <code class="bash spaces">   </code> <code class="bash plain">server {</code> </div> <div class="line number36 index35 alt1"> <code class="bash spaces">        </code> <code class="bash plain">listen 8080;</code> </div> <div class="line number37 index36 alt2"> <code class="bash spaces">        </code> <code class="bash plain">server_name 127.0.0.1;</code> </div> <div class="line number38 index37 alt1"> <code class="bash spaces">        </code> <code class="bash plain">location / {</code> </div> <div class="line number39 index38 alt2"> <code class="bash spaces">                </code> <code class="bash plain">root </code> <code class="bash plain">/www/html/b</code> <code class="bash plain">;</code> </div> <div class="line number40 index39 alt1"> <code class="bash spaces">                </code> <code class="bash plain">index index.html index.htm;</code> </div> <div class="line number41 index40 alt2"> <code class="bash spaces">        </code> <code class="bash plain">}</code> </div> <div class="line number42 index41 alt1"> <code class="bash spaces">   </code> <code class="bash plain">}</code> </div> <div class="line number43 index42 alt2"> <code class="bash spaces">   </code>  </div> <div class="line number44 index43 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># curl http://www.c.net</code> </div> <div class="line number45 index44 alt2"> <code class="bash plain">192.168.9.11</code> </div> <div class="line number46 index45 alt1"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># curl http://www.c.net</code> </div> <div class="line number47 index46 alt2"> <code class="bash plain">192.168.9.13 </code> </div> <div class="line number48 index47 alt1"> <code class="bash comments">##停掉上游两台服务器后:</code> </div> <div class="line number49 index48 alt2"> <code class="bash plain">[root@mail ~]</code> <code class="bash comments"># curl http://www.c.net</code> </div> <div class="line number50 index49 alt1"> <code class="bash plain">Sorry</code> </div> <div class="line number51 index50 alt2">   </div> <div class="line number52 index51 alt1"> <code class="bash comments">#####Nginx的基本功能基本完成</code> </div></td> </tr> </tbody> </table> <p>The end</p> <p>有关Nginx的基本配置及一般用法就写到这里了,第一次写Nginx的博客,写的比较乱,比较杂,敬请谅解,有什么不对的地方,麻烦朋友们告诉我。以上为个人学习整理,如有错漏,大神勿喷。。。。。</p> <p><br></p> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1249815974107009024"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(使用,基本,Nginx,Linux)</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1835513699826233344.htm" title="android系统selinux中添加新属性property" target="_blank">android系统selinux中添加新属性property</a> <span class="text-muted">辉色投像</span> <div>1.定位/android/system/sepolicy/private/property_contexts声明属性开头:persist.charge声明属性类型:u:object_r:system_prop:s0图12.定位到android/system/sepolicy/public/domain.te删除neverallow{domain-init}default_prop:property</div> </li> <li><a href="/article/1835512920797179904.htm" title="element实现动态路由+面包屑" target="_blank">element实现动态路由+面包屑</a> <span class="text-muted">软件技术NINI</span> <a class="tag" taget="_blank" href="/search/vue%E6%A1%88%E4%BE%8B/1.htm">vue案例</a><a class="tag" taget="_blank" href="/search/vue.js/1.htm">vue.js</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>el-breadcrumb是ElementUI组件库中的一个面包屑导航组件,它用于显示当前页面的路径,帮助用户快速理解和导航到应用的各个部分。在Vue.js项目中,如果你已经安装了ElementUI,就可以很方便地使用el-breadcrumb组件。以下是一个基本的使用示例:安装ElementUI(如果你还没有安装的话):你可以通过npm或yarn来安装ElementUI。bash复制代码npmi</div> </li> <li><a href="/article/1835512542735200256.htm" title="C语言宏函数" target="_blank">C语言宏函数</a> <span class="text-muted">南林yan</span> <a class="tag" taget="_blank" href="/search/C%E8%AF%AD%E8%A8%80/1.htm">C语言</a><a class="tag" taget="_blank" href="/search/c%E8%AF%AD%E8%A8%80/1.htm">c语言</a> <div>一、什么是宏函数?通过宏定义的函数是宏函数。如下,编译器在预处理阶段会将Add(x,y)替换为((x)*(y))#defineAdd(x,y)((x)*(y))#defineAdd(x,y)((x)*(y))intmain(){inta=10;intb=20;intd=10;intc=Add(a+d,b)*2;cout<<c<<endl;//800return0;}二、为什么要使用宏函数使用宏函数</div> </li> <li><a href="/article/1835511911769272320.htm" title="C语言如何定义宏函数?" target="_blank">C语言如何定义宏函数?</a> <span class="text-muted">小九格物</span> <a class="tag" taget="_blank" href="/search/c%E8%AF%AD%E8%A8%80/1.htm">c语言</a> <div>在C语言中,宏函数是通过预处理器定义的,它在编译之前替换代码中的宏调用。宏函数可以模拟函数的行为,但它们不是真正的函数,因为它们在编译时不会进行类型检查,也不会分配存储空间。宏函数的定义通常使用#define指令,后面跟着宏的名称和参数列表,以及宏展开后的代码。宏函数的定义方式:1.基本宏函数:这是最简单的宏函数形式,它直接定义一个表达式。#defineSQUARE(x)((x)*(x))2.带参</div> </li> <li><a href="/article/1835511912843014144.htm" title="理解Gunicorn:Python WSGI服务器的基石" target="_blank">理解Gunicorn:Python WSGI服务器的基石</a> <span class="text-muted">范范0825</span> <a class="tag" taget="_blank" href="/search/ipython/1.htm">ipython</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a> <div>理解Gunicorn:PythonWSGI服务器的基石介绍Gunicorn,全称GreenUnicorn,是一个为PythonWSGI(WebServerGatewayInterface)应用设计的高效、轻量级HTTP服务器。作为PythonWeb应用部署的常用工具,Gunicorn以其高性能和易用性著称。本文将介绍Gunicorn的基本概念、安装和配置,帮助初学者快速上手。1.什么是Gunico</div> </li> <li><a href="/article/1835511542284644352.htm" title="学点心理知识,呵护孩子健康" target="_blank">学点心理知识,呵护孩子健康</a> <span class="text-muted">静候花开_7090</span> <div>昨天听了华中师范大学教育管理学系副教授张玲老师的《哪里才是学生心理健康的最后庇护所,超越教育与技术的思考》的讲座。今天又重新学习了一遍,收获匪浅。张玲博士也注意到了当今社会上的孩子由于心理问题导致的自残、自杀及伤害他人等恶性事件。她向我们普及了一个重要的命题,她说心理健康的一些基本命题,我们与我们通常的一些教育命题是不同的,她还举了几个例子,让我们明白我们原来以为的健康并非心理学上的健康。比如如果</div> </li> <li><a href="/article/1835511030260789248.htm" title="c++ 的iostream 和 c++的stdio的区别和联系" target="_blank">c++ 的iostream 和 c++的stdio的区别和联系</a> <span class="text-muted">黄卷青灯77</span> <a class="tag" taget="_blank" href="/search/c%2B%2B/1.htm">c++</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/iostream/1.htm">iostream</a><a class="tag" taget="_blank" href="/search/stdio/1.htm">stdio</a> <div>在C++中,iostream和C语言的stdio.h都是用于处理输入输出的库,但它们在设计、用法和功能上有许多不同。以下是两者的区别和联系:区别1.编程风格iostream(C++风格):C++标准库中的输入输出流类库,支持面向对象的输入输出操作。典型用法是cin(输入)和cout(输出),使用>操作符来处理数据。更加类型安全,支持用户自定义类型的输入输出。#includeintmain(){in</div> </li> <li><a href="/article/1835509897106649088.htm" title="Long类型前后端数据不一致" target="_blank">Long类型前后端数据不一致</a> <span class="text-muted">igotyback</span> <a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>响应给前端的数据浏览器控制台中response中看到的Long类型的数据是正常的到前端数据不一致前后端数据类型不匹配是一个常见问题,尤其是当后端使用Java的Long类型(64位)与前端JavaScript的Number类型(最大安全整数为2^53-1,即16位)进行数据交互时,很容易出现精度丢失的问题。这是因为JavaScript中的Number类型无法安全地表示超过16位的整数。为了解决这个问</div> </li> <li><a href="/article/1835509391361667072.htm" title="Linux下QT开发的动态库界面弹出操作(SDL2)" target="_blank">Linux下QT开发的动态库界面弹出操作(SDL2)</a> <span class="text-muted">13jjyao</span> <a class="tag" taget="_blank" href="/search/QT%E7%B1%BB/1.htm">QT类</a><a class="tag" taget="_blank" href="/search/qt/1.htm">qt</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/sdl2/1.htm">sdl2</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>需求:操作系统为linux,开发框架为qt,做成需带界面的qt动态库,调用方为java等非qt程序难点:调用方为java等非qt程序,也就是说调用方肯定不带QApplication::exec(),缺少了这个,QTimer等事件和QT创建的窗口将不能弹出(包括opencv也是不能弹出);这与qt调用本身qt库是有本质的区别的思路:1.调用方缺QApplication::exec(),那么我们在接口</div> </li> <li><a href="/article/1835508130268672000.htm" title="消息中间件有哪些常见类型" target="_blank">消息中间件有哪些常见类型</a> <span class="text-muted">xmh-sxh-1314</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>消息中间件根据其设计理念和用途,可以大致分为以下几种常见类型:点对点消息队列(Point-to-PointMessagingQueues):在这种模型中,消息被发送到特定的队列中,消费者从队列中取出并处理消息。队列中的消息只能被一个消费者消费,消费后即被删除。常见的实现包括IBM的MQSeries、RabbitMQ的部分使用场景等。适用于任务分发、负载均衡等场景。发布/订阅消息模型(Pub/Sub</div> </li> <li><a href="/article/1835508130608410624.htm" title="html 中如何使用 uniapp 的部分方法" target="_blank">html 中如何使用 uniapp 的部分方法</a> <span class="text-muted">某公司摸鱼前端</span> <a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/uni-app/1.htm">uni-app</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>示例代码:Documentconsole.log(window);效果展示:好了,现在就可以uni.使用相关的方法了</div> </li> <li><a href="/article/1835508131032035328.htm" title="ArcGIS栅格计算器常见公式(赋值、0和空值的转换、补充栅格空值)" target="_blank">ArcGIS栅格计算器常见公式(赋值、0和空值的转换、补充栅格空值)</a> <span class="text-muted">研学随笔</span> <a class="tag" taget="_blank" href="/search/arcgis/1.htm">arcgis</a><a class="tag" taget="_blank" href="/search/%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB/1.htm">经验分享</a> <div>我们在使用ArcGIS时通常经常用到栅格计算器,今天主要给大家介绍我日常中经常用到的几个公式,供大家参考学习。将特定值(-9999)赋值为0,例如-9999.Con("raster"==-9999,0,"raster")2.给空值赋予特定的值(如0)Con(IsNull("raster"),0,"raster")3.将特定的栅格值(如1)赋值为空值,其他保留原值SetNull("raster"==</div> </li> <li><a href="/article/1835508131489214464.htm" title="高级编程--XML+socket练习题" target="_blank">高级编程--XML+socket练习题</a> <span class="text-muted">masa010</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>1.北京华北2114.8万人上海华东2,500万人广州华南1292.68万人成都华西1417万人(1)使用dom4j将信息存入xml中(2)读取信息,并打印控制台(3)添加一个city节点与子节点(4)使用socketTCP协议编写服务端与客户端,客户端输入城市ID,服务器响应相应城市信息(5)使用socketTCP协议编写服务端与客户端,客户端要求用户输入city对象,服务端接收并使用dom4j</div> </li> <li><a href="/article/1835508123746529280.htm" title="那个抄袭的大张伟" target="_blank">那个抄袭的大张伟</a> <span class="text-muted">猫小努</span> <div>最近一直在追《即刻电音》这个综艺,除了觉得出场节目的音乐制作人有意思之外,也觉得有两个导师挺有趣的(另外一个就忽略了吧)。孙艺兴在上一篇文章里面已经说过了,那么这篇就说说我们的大老师,大张伟吧。其实在节目刚开始大张伟出来的时候,我以为他是属于导师里面来活跃气氛负责搞笑的,毕竟孙艺兴属于卖萌卖傻卖老实的,尚雯婕一般负责装逼耍狠的,而大张伟一贯以来上综艺的形象基本上都是蹦蹦跳跳带动气氛的。谁知道,两期</div> </li> <li><a href="/article/1835507626276909056.htm" title="水平垂直居中的几种方法(总结)" target="_blank">水平垂直居中的几种方法(总结)</a> <span class="text-muted">LJ小番茄</span> <a class="tag" taget="_blank" href="/search/CSS_%E7%8E%84%E5%AD%A6%E8%AF%AD%E8%A8%80/1.htm">CSS_玄学语言</a><a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a><a class="tag" taget="_blank" href="/search/css3/1.htm">css3</a> <div>1.使用flexbox的justify-content和align-items.parent{display:flex;justify-content:center;/*水平居中*/align-items:center;/*垂直居中*/height:100vh;/*需要指定高度*/}2.使用grid的place-items:center.parent{display:grid;place-item</div> </li> <li><a href="/article/1835507248395284480.htm" title="【一起学Rust | 设计模式】习惯语法——使用借用类型作为参数、格式化拼接字符串、构造函数" target="_blank">【一起学Rust | 设计模式】习惯语法——使用借用类型作为参数、格式化拼接字符串、构造函数</a> <span class="text-muted">广龙宇</span> <a class="tag" taget="_blank" href="/search/%E4%B8%80%E8%B5%B7%E5%AD%A6Rust/1.htm">一起学Rust</a><a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Rust%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">Rust设计模式</a><a class="tag" taget="_blank" href="/search/rust/1.htm">rust</a><a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录前言一、使用借用类型作为参数二、格式化拼接字符串三、使用构造函数总结前言Rust不是传统的面向对象编程语言,它的所有特性,使其独一无二。因此,学习特定于Rust的设计模式是必要的。本系列文章为作者学习《Rust设计模式》的学习笔记以及自己的见解。因此,本系列文章的结构也与此书的结构相同(后续可能会调成结构),基本上分为三个部分</div> </li> <li><a href="/article/1835506869838376960.htm" title="Python数据分析与可视化实战指南" target="_blank">Python数据分析与可视化实战指南</a> <span class="text-muted">William数据分析</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE/1.htm">数据</a> <div>在数据驱动的时代,Python因其简洁的语法、强大的库生态系统以及活跃的社区,成为了数据分析与可视化的首选语言。本文将通过一个详细的案例,带领大家学习如何使用Python进行数据分析,并通过可视化来直观呈现分析结果。一、环境准备1.1安装必要库在开始数据分析和可视化之前,我们需要安装一些常用的库。主要包括pandas、numpy、matplotlib和seaborn等。这些库分别用于数据处理、数学</div> </li> <li><a href="/article/1835506236842405888.htm" title="C#中使用split分割字符串" target="_blank">C#中使用split分割字符串</a> <span class="text-muted">互联网打工人no1</span> <a class="tag" taget="_blank" href="/search/c%23/1.htm">c#</a> <div>1、用字符串分隔:usingSystem.Text.RegularExpressions;stringstr="aaajsbbbjsccc";string[]sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);foreach(stringiinsArray)Response.Write(i.ToString()+"");输出结果:aaabbbc</div> </li> <li><a href="/article/1835505858444881920.htm" title="git常用命令笔记" target="_blank">git常用命令笔记</a> <span class="text-muted">咩酱-小羊</span> <a class="tag" taget="_blank" href="/search/git/1.htm">git</a><a class="tag" taget="_blank" href="/search/%E7%AC%94%E8%AE%B0/1.htm">笔记</a> <div>###用习惯了idea总是不记得git的一些常见命令,需要用到的时候总是担心旁边站了人~~~记个笔记@_@,告诉自己看笔记不丢人初始化初始化一个新的Git仓库gitinit配置配置用户信息gitconfig--globaluser.name"YourName"gitconfig--globaluser.email"youremail@example.com"基本操作克隆远程仓库gitclone查看</div> </li> <li><a href="/article/1835505606245576704.htm" title="Python中os.environ基本介绍及使用方法" target="_blank">Python中os.environ基本介绍及使用方法</a> <span class="text-muted">鹤冲天Pro</span> <a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>文章目录python中os.environos.environ简介os.environ进行环境变量的增删改查python中os.environ的使用详解1.简介2.key字段详解2.1常见key字段3.os.environ.get()用法4.环境变量的增删改查和判断是否存在4.1新增环境变量4.2更新环境变量4.3获取环境变量4.4删除环境变量4.5判断环境变量是否存在python中os.envi</div> </li> <li><a href="/article/1835504596898902016.htm" title="linux sdl windows.h,Windows下的SDL安装" target="_blank">linux sdl windows.h,Windows下的SDL安装</a> <span class="text-muted">奔跑吧linux内核</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/sdl/1.htm">sdl</a><a class="tag" taget="_blank" href="/search/windows.h/1.htm">windows.h</a> <div>首先你要下载并安装SDL开发包。如果装在C盘下,路径为C:\SDL1.2.5如果在WINDOWS下。你可以按以下步骤:1.打开VC++,点击"Tools",Options2,点击directories选项3.选择"Includefiles"增加一个新的路径。"C:\SDL1.2.5\include"4,现在选择"Libaryfiles“增加"C:\SDL1.2.5\lib"现在你可以开始编写你的第</div> </li> <li><a href="/article/1835504217729626112.htm" title="Python教程:一文了解使用Python处理XPath" target="_blank">Python教程:一文了解使用Python处理XPath</a> <span class="text-muted">旦莫</span> <a class="tag" taget="_blank" href="/search/Python%E8%BF%9B%E9%98%B6/1.htm">Python进阶</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>目录1.环境准备1.1安装lxml1.2验证安装2.XPath基础2.1什么是XPath?2.2XPath语法2.3示例XML文档3.使用lxml解析XML3.1解析XML文档3.2查看解析结果4.XPath查询4.1基本路径查询4.2使用属性查询4.3查询多个节点5.XPath的高级用法5.1使用逻辑运算符5.2使用函数6.实战案例6.1从网页抓取数据6.1.1安装Requests库6.1.2代</div> </li> <li><a href="/article/1835504218178416640.htm" title="Google earth studio 简介" target="_blank">Google earth studio 简介</a> <span class="text-muted">陟彼高冈yu</span> <a class="tag" taget="_blank" href="/search/%E6%97%85%E6%B8%B8/1.htm">旅游</a> <div>GoogleEarthStudio是一个基于Web的动画工具,专为创作使用GoogleEarth数据的动画和视频而设计。它利用了GoogleEarth强大的三维地图和卫星影像数据库,使用户能够轻松地创建逼真的地球动画、航拍视频和动态地图可视化。网址为https://www.google.com/earth/studio/。GoogleEarthStudio是一个基于Web的动画工具,专为创作使用G</div> </li> <li><a href="/article/1835503712899002368.htm" title="linux中sdl的使用教程,sdl使用入门" target="_blank">linux中sdl的使用教程,sdl使用入门</a> <span class="text-muted">Melissa Corvinus</span> <a class="tag" taget="_blank" href="/search/linux%E4%B8%ADsdl%E7%9A%84%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/1.htm">linux中sdl的使用教程</a> <div>本文通过一个简单示例讲解SDL的基本使用流程。示例中展示一个窗口,窗口里面有个随机颜色快随机移动。当我们鼠标点击关闭按钮时间窗口关闭。基本步骤如下:1.初始化SDL并创建一个窗口。SDL_Init()初始化SDL_CreateWindow()创建窗口2.纹理渲染存储RGB和存储纹理的区别:比如一个从左到右由红色渐变到蓝色的矩形,用存储RGB的话就需要把矩形中每个点的具体颜色值存储下来;而纹理只是一</div> </li> <li><a href="/article/1835502705553010688.htm" title="LLM 词汇表" target="_blank">LLM 词汇表</a> <span class="text-muted">落难Coder</span> <a class="tag" taget="_blank" href="/search/LLMs/1.htm">LLMs</a><a class="tag" taget="_blank" href="/search/NLP/1.htm">NLP</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B/1.htm">大语言模型</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%A8%A1%E5%9E%8B/1.htm">大模型</a><a class="tag" taget="_blank" href="/search/llama/1.htm">llama</a><a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a> <div>Contextwindow“上下文窗口”是指语言模型在生成新文本时能够回溯和参考的文本量。这不同于语言模型训练时所使用的大量数据集,而是代表了模型的“工作记忆”。较大的上下文窗口可以让模型理解和响应更复杂和更长的提示,而较小的上下文窗口可能会限制模型处理较长提示或在长时间对话中保持连贯性的能力。Fine-tuning微调是使用额外的数据进一步训练预训练语言模型的过程。这使得模型开始表示和模仿微调数</div> </li> <li><a href="/article/1835502704827396096.htm" title="将cmd中命令输出保存为txt文本文件" target="_blank">将cmd中命令输出保存为txt文本文件</a> <span class="text-muted">落难Coder</span> <a class="tag" taget="_blank" href="/search/Windows/1.htm">Windows</a><a class="tag" taget="_blank" href="/search/cmd/1.htm">cmd</a><a class="tag" taget="_blank" href="/search/window/1.htm">window</a> <div>最近深度学习本地的训练中我们常常要在命令行中运行自己的代码,无可厚非,我们有必要保存我们的炼丹结果,但是复制命令行输出到txt是非常麻烦的,其实Windows下的命令行为我们提供了相应的操作。其基本的调用格式就是:运行指令>输出到的文件名称或者具体保存路径测试下,我打开cmd并且ping一下百度:pingwww.baidu.com>./data.txt看下相同目录下data.txt的输出:如果你再</div> </li> <li><a href="/article/1835502578050363392.htm" title="PHP环境搭建详细教程" target="_blank">PHP环境搭建详细教程</a> <span class="text-muted">好看资源平台</span> <a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/php/1.htm">php</a> <div>PHP是一个流行的服务器端脚本语言,广泛用于Web开发。为了使PHP能够在本地或服务器上运行,我们需要搭建一个合适的PHP环境。本教程将结合最新资料,介绍在不同操作系统上搭建PHP开发环境的多种方法,包括Windows、macOS和Linux系统的安装步骤,以及本地和Docker环境的配置。1.PHP环境搭建概述PHP环境的搭建主要分为以下几类:集成开发环境:例如XAMPP、WAMP、MAMP,这</div> </li> <li><a href="/article/1835502578511736832.htm" title="下载github patch到本地" target="_blank">下载github patch到本地</a> <span class="text-muted">小米人er</span> <a class="tag" taget="_blank" href="/search/%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/1.htm">我的博客</a><a class="tag" taget="_blank" href="/search/git/1.htm">git</a><a class="tag" taget="_blank" href="/search/patch/1.htm">patch</a> <div>以下是几种从GitHub上下载以.patch结尾的补丁文件的方法:通过浏览器直接下载打开包含该.patch文件的GitHub仓库。在仓库的文件列表中找到对应的.patch文件。点击该文件,浏览器会显示文件的内容,在页面的右上角通常会有一个“Raw”按钮,点击它可以获取原始文件内容。然后在浏览器中使用快捷键(如Ctrl+S或者Command+S)将原始文件保存到本地,选择保存的文件名并确保后缀为.p</div> </li> <li><a href="/article/1835501948011376640.htm" title="使用 FinalShell 进行远程连接(ssh 远程连接 Linux 服务器)" target="_blank">使用 FinalShell 进行远程连接(ssh 远程连接 Linux 服务器)</a> <span class="text-muted">编程经验分享</span> <a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/1.htm">开发工具</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/ssh/1.htm">ssh</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>目录前言基本使用教程新建远程连接连接主机自定义命令路由追踪前言后端开发,必然需要和服务器打交道,部署应用,排查问题,查看运行日志等等。一般服务器都是集中部署在机房中,也有一些直接是云服务器,总而言之,程序员不可能直接和服务器直接操作,一般都是通过ssh连接来登录服务器。刚接触远程连接时,使用的是XSHELL来远程连接服务器,连接上就能够操作远程服务器了,但是仅用XSHELL并没有上传下载文件的功能</div> </li> <li><a href="/article/1835501821569888256.htm" title="关于提高复杂业务逻辑代码可读性的思考" target="_blank">关于提高复杂业务逻辑代码可读性的思考</a> <span class="text-muted">编程经验分享</span> <a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E7%BB%8F%E9%AA%8C/1.htm">开发经验</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>目录前言需求场景常规写法拆分方法领域对象总结前言实际工作中大部分时间都是在写业务逻辑,一般都是三层架构,表示层(Controller)接收客户端请求,并对入参做检验,业务逻辑层(Service)负责处理业务逻辑,一般开发都是在这一层中写具体的业务逻辑。数据访问层(Dao)是直接和数据库交互的,用于查数据给业务逻辑层,或者是将业务逻辑层处理后的数据写入数据库。简单的增删改查接口不用多说,基本上写好一</div> </li> <li><a href="/article/73.htm" title="Hadoop(一)" target="_blank">Hadoop(一)</a> <span class="text-muted">朱辉辉33</span> <a class="tag" taget="_blank" href="/search/hadoop/1.htm">hadoop</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a> <div>今天在诺基亚第一天开始培训大数据,因为之前没接触过Linux,所以这次一起学了,任务量还是蛮大的。 首先下载安装了Xshell软件,然后公司给了账号密码连接上了河南郑州那边的服务器,接下来开始按照给的资料学习,全英文的,头也不讲解,说锻炼我们的学习能力,然后就开始跌跌撞撞的自学。这里写部分已经运行成功的代码吧.    在hdfs下,运行hadoop fs -mkdir /u</div> </li> <li><a href="/article/200.htm" title="maven An error occurred while filtering resources" target="_blank">maven An error occurred while filtering resources</a> <span class="text-muted">blackproof</span> <a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a><a class="tag" taget="_blank" href="/search/%E6%8A%A5%E9%94%99/1.htm">报错</a> <div>转:http://stackoverflow.com/questions/18145774/eclipse-an-error-occurred-while-filtering-resources   maven报错: maven An error occurred while filtering resources   Maven -> Update Proje</div> </li> <li><a href="/article/327.htm" title="jdk常用故障排查命令" target="_blank">jdk常用故障排查命令</a> <span class="text-muted">daysinsun</span> <a class="tag" taget="_blank" href="/search/jvm/1.htm">jvm</a> <div>linux下常见定位命令: 1、jps      输出Java进程       -q       只输出进程ID的名称,省略主类的名称;       -m      输出进程启动时传递给main函数的参数;     &nb</div> </li> <li><a href="/article/454.htm" title="java 位移运算与乘法运算" target="_blank">java 位移运算与乘法运算</a> <span class="text-muted">周凡杨</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E4%BD%8D%E7%A7%BB/1.htm">位移</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%AE%97/1.htm">运算</a><a class="tag" taget="_blank" href="/search/%E4%B9%98%E6%B3%95/1.htm">乘法</a> <div>  对于 JAVA 编程中,适当的采用位移运算,会减少代码的运行时间,提高项目的运行效率。这个可以从一道面试题说起:     问题: 用最有效率的方法算出2 乘以8 等於几?” 答案:2 << 3 由此就引发了我的思考,为什么位移运算会比乘法运算更快呢?其实简单的想想,计算机的内存是用由 0 和 1 组成的二</div> </li> <li><a href="/article/581.htm" title="java中的枚举(enmu)" target="_blank">java中的枚举(enmu)</a> <span class="text-muted">g21121</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>从jdk1.5开始,java增加了enum(枚举)这个类型,但是大家在平时运用中还是比较少用到枚举的,而且很多人和我一样对枚举一知半解,下面就跟大家一起学习下enmu枚举。先看一个最简单的枚举类型,一个返回类型的枚举: public enum ResultType { /** * 成功 */ SUCCESS, /** * 失败 */ FAIL, </div> </li> <li><a href="/article/708.htm" title="MQ初级学习" target="_blank">MQ初级学习</a> <span class="text-muted">510888780</span> <a class="tag" taget="_blank" href="/search/activemq/1.htm">activemq</a> <div>1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.9.0-bin.zip到C盘,然后双击apache-activemq-5.9.0-\bin\activemq-admin.bat运行ActiveMQ程序。 启动ActiveMQ以后,登陆:http://localhos</div> </li> <li><a href="/article/835.htm" title="Spring_Transactional_Propagation" target="_blank">Spring_Transactional_Propagation</a> <span class="text-muted">布衣凌宇</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/transactional/1.htm">transactional</a> <div>//事务传播属性 @Transactional(propagation=Propagation.REQUIRED)//如果有事务,那么加入事务,没有的话新创建一个 @Transactional(propagation=Propagation.NOT_SUPPORTED)//这个方法不开启事务 @Transactional(propagation=Propagation.REQUIREDS_N</div> </li> <li><a href="/article/962.htm" title="我的spring学习笔记12-idref与ref的区别" target="_blank">我的spring学习笔记12-idref与ref的区别</a> <span class="text-muted">aijuans</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a> <div>idref用来将容器内其他bean的id传给<constructor-arg>/<property>元素,同时提供错误验证功能。例如: <bean id ="theTargetBean" class="..." /> <bean id ="theClientBean" class=&quo</div> </li> <li><a href="/article/1089.htm" title="Jqplot之折线图" target="_blank">Jqplot之折线图</a> <span class="text-muted">antlove</span> <a class="tag" taget="_blank" href="/search/js/1.htm">js</a><a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/timeseries/1.htm">timeseries</a><a class="tag" taget="_blank" href="/search/jqplot/1.htm">jqplot</a> <div>timeseriesChart.html <script type="text/javascript" src="jslib/jquery.min.js"></script> <script type="text/javascript" src="jslib/excanvas.min.js&</div> </li> <li><a href="/article/1216.htm" title="JDBC中事务处理应用" target="_blank">JDBC中事务处理应用</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/JDBC%E7%BC%96%E7%A8%8B/1.htm">JDBC编程</a><a class="tag" taget="_blank" href="/search/%E4%BA%8B%E5%8A%A1%E6%8E%A7%E5%88%B6%E8%AF%AD%E5%8F%A5/1.htm">事务控制语句</a> <div>  解释事务的概念; 事务控制是sql语句中的核心之一;事务控制的作用就是保证数据的正常执行与异常之后可以恢复   事务常用命令:             Commit提交         </div> </li> <li><a href="/article/1343.htm" title="[转]ConcurrentHashMap Collections.synchronizedMap和Hashtable讨论" target="_blank">[转]ConcurrentHashMap Collections.synchronizedMap和Hashtable讨论</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%A4%9A%E7%BA%BF%E7%A8%8B/1.htm">多线程</a><a class="tag" taget="_blank" href="/search/%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8/1.htm">线程安全</a><a class="tag" taget="_blank" href="/search/HashMap/1.htm">HashMap</a> <div>在Java类库中出现的第一个关联的集合类是Hashtable,它是JDK1.0的一部分。 Hashtable提供了一种易于使用的、线程安全的、关联的map功能,这当然也是方便的。然而,线程安全性是凭代价换来的――Hashtable的所有方法都是同步的。此时,无竞争的同步会导致可观的性能代价。Hashtable的后继者HashMap是作为JDK1.2中的集合框架的一部分出现的,它通过提供一个不同步的</div> </li> <li><a href="/article/1470.htm" title="ng-if与ng-show、ng-hide指令的区别和注意事项" target="_blank">ng-if与ng-show、ng-hide指令的区别和注意事项</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/AngularJS/1.htm">AngularJS</a> <div>        angularJS中的ng-show、ng-hide、ng-if指令都可以用来控制dom元素的显示或隐藏。ng-show和ng-hide根据所给表达式的值来显示或隐藏HTML元素。当赋值给ng-show指令的值为false时元素会被隐藏,值为true时元素会显示。ng-hide功能类似,使用方式相反。元素的显示或</div> </li> <li><a href="/article/1597.htm" title="【持久化框架MyBatis3七】MyBatis3定义typeHandler" target="_blank">【持久化框架MyBatis3七】MyBatis3定义typeHandler</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/TypeHandler/1.htm">TypeHandler</a> <div>什么是typeHandler? typeHandler用于将某个类型的数据映射到表的某一列上,以完成MyBatis列跟某个属性的映射   内置typeHandler MyBatis内置了很多typeHandler,这写typeHandler通过org.apache.ibatis.type.TypeHandlerRegistry进行注册,比如对于日期型数据的typeHandler, </div> </li> <li><a href="/article/1724.htm" title="上传下载文件rz,sz命令" target="_blank">上传下载文件rz,sz命令</a> <span class="text-muted">bitcarter</span> <a class="tag" taget="_blank" href="/search/linux%E5%91%BD%E4%BB%A4rz/1.htm">linux命令rz</a> <div>刚开始使用rz上传和sz下载命令: 因为我们是通过secureCRT终端工具进行使用的所以会有上传下载这样的需求: 我遇到的问题: sz下载A文件10M左右,没有问题 但是将这个文件A再传到另一天服务器上时就出现传不上去,甚至出现乱码,死掉现象,具体问题 解决方法: 上传命令改为;rz -ybe 下载命令改为:sz -be filename 如果还是有问题: 那就是文</div> </li> <li><a href="/article/1851.htm" title="通过ngx-lua来统计nginx上的虚拟主机性能数据" target="_blank">通过ngx-lua来统计nginx上的虚拟主机性能数据</a> <span class="text-muted">ronin47</span> <a class="tag" taget="_blank" href="/search/ngx-lua%E3%80%80%E7%BB%9F%E8%AE%A1+%E8%A7%A3%E7%A6%81ip/1.htm">ngx-lua 统计 解禁ip</a> <div>介绍 以前我们为nginx做统计,都是通过对日志的分析来完成.比较麻烦,现在基于ngx_lua插件,开发了实时统计站点状态的脚本,解放生产力.项目主页: https://github.com/skyeydemon/ngx-lua-stats 功能 支持分不同虚拟主机统计, 同一个虚拟主机下可以分不同的location统计. 可以统计与query-times request-time </div> </li> <li><a href="/article/1978.htm" title="java-68-把数组排成最小的数。一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的。例如输入数组{32, 321},则输出32132" target="_blank">java-68-把数组排成最小的数。一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的。例如输入数组{32, 321},则输出32132</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div> import java.util.Arrays; import java.util.Comparator; public class MinNumFromIntArray { /** * Q68输入一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的一个。 * 例如输入数组{32, 321},则输出这两个能排成的最小数字32132。请给出解决问题</div> </li> <li><a href="/article/2105.htm" title="Oracle基本操作" target="_blank">Oracle基本操作</a> <span class="text-muted">ccii</span> <a class="tag" taget="_blank" href="/search/Oracle+SQL%E6%80%BB%E7%BB%93/1.htm">Oracle SQL总结</a><a class="tag" taget="_blank" href="/search/Oracle+SQL%E8%AF%AD%E6%B3%95/1.htm">Oracle SQL语法</a><a class="tag" taget="_blank" href="/search/Oracle%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C/1.htm">Oracle基本操作</a><a class="tag" taget="_blank" href="/search/Oracle+SQL/1.htm">Oracle SQL</a> <div>一、表操作 1. 常用数据类型 NUMBER(p,s):可变长度的数字。p表示整数加小数的最大位数,s为最大小数位数。支持最大精度为38位 NVARCHAR2(size):变长字符串,最大长度为4000字节(以字符数为单位) VARCHAR2(size):变长字符串,最大长度为4000字节(以字节数为单位) CHAR(size):定长字符串,最大长度为2000字节,最小为1字节,默认</div> </li> <li><a href="/article/2232.htm" title="[强人工智能]实现强人工智能的路线图" target="_blank">[强人工智能]实现强人工智能的路线图</a> <span class="text-muted">comsci</span> <a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a> <div>     1:创建一个用于记录拓扑网络连接的矩阵数据表      2:自动构造或者人工复制一个包含10万个连接(1000*1000)的流程图      3:将这个流程图导入到矩阵数据表中      4:在矩阵的每个有意义的节点中嵌入一段简单的</div> </li> <li><a href="/article/2359.htm" title="给Tomcat,Apache配置gzip压缩(HTTP压缩)功能" target="_blank">给Tomcat,Apache配置gzip压缩(HTTP压缩)功能</a> <span class="text-muted">cwqcwqmax9</span> <a class="tag" taget="_blank" href="/search/apache/1.htm">apache</a> <div>背景: HTTP 压缩可以大大提高浏览网站的速度,它的原理是,在客户端请求网页后,从服务器端将网页文件压缩,再下载到客户端,由客户端的浏览器负责解压缩并浏览。相对于普通的浏览过程HTML ,CSS,Javascript , Text ,它可以节省40%左右的流量。更为重要的是,它可以对动态生成的,包括CGI、PHP , JSP , ASP , Servlet,SHTML等输出的网页也能进行压缩,</div> </li> <li><a href="/article/2486.htm" title="SpringMVC and Struts2" target="_blank">SpringMVC and Struts2</a> <span class="text-muted">dashuaifu</span> <a class="tag" taget="_blank" href="/search/struts2/1.htm">struts2</a><a class="tag" taget="_blank" href="/search/springMVC/1.htm">springMVC</a> <div>SpringMVC VS Struts2 1: spring3开发效率高于struts 2: spring3 mvc可以认为已经100%零配置 3: struts2是类级别的拦截, 一个类对应一个request上下文, springmvc是方法级别的拦截,一个方法对应一个request上下文,而方法同时又跟一个url对应 所以说从架构本身上 spring3 mvc就容易实现r</div> </li> <li><a href="/article/2613.htm" title="windows常用命令行命令" target="_blank">windows常用命令行命令</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/windows/1.htm">windows</a><a class="tag" taget="_blank" href="/search/cmd/1.htm">cmd</a><a class="tag" taget="_blank" href="/search/command/1.htm">command</a> <div>在windows系统中,点击开始-运行,可以直接输入命令行,快速打开一些原本需要多次点击图标才能打开的界面,如常用的输入cmd打开dos命令行,输入taskmgr打开任务管理器。此处列出了网上搜集到的一些常用命令。winver 检查windows版本 wmimgmt.msc 打开windows管理体系结构(wmi) wupdmgr windows更新程序 wscrip</div> </li> <li><a href="/article/2740.htm" title="再看知名应用背后的第三方开源项目" target="_blank">再看知名应用背后的第三方开源项目</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/ios/1.htm">ios</a> <div>知名应用程序的设计和技术一直都是开发者需要学习的,同样这些应用所使用的开源框架也是不可忽视的一部分。此前《 iOS第三方开源库的吐槽和备忘》中作者ibireme列举了国内多款知名应用所使用的开源框架,并对其中一些框架进行了分析,同样国外开发者 @iOSCowboy也在博客中给我们列出了国外多款知名应用使用的开源框架。另外txx's blog中详细介绍了 Facebook Paper使用的第三</div> </li> <li><a href="/article/2867.htm" title="Objective-c单例模式的正确写法" target="_blank">Objective-c单例模式的正确写法</a> <span class="text-muted">jsntghf</span> <a class="tag" taget="_blank" href="/search/%E5%8D%95%E4%BE%8B/1.htm">单例</a><a class="tag" taget="_blank" href="/search/ios/1.htm">ios</a><a class="tag" taget="_blank" href="/search/iPhone/1.htm">iPhone</a> <div>一般情况下,可能我们写的单例模式是这样的: #import <Foundation/Foundation.h> @interface Downloader : NSObject + (instancetype)sharedDownloader; @end #import "Downloader.h" @implementation</div> </li> <li><a href="/article/2994.htm" title="jquery easyui datagrid 加载成功,选中某一行" target="_blank">jquery easyui datagrid 加载成功,选中某一行</a> <span class="text-muted">hae</span> <a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/easyui/1.htm">easyui</a><a class="tag" taget="_blank" href="/search/datagrid/1.htm">datagrid</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%8A%A0%E8%BD%BD/1.htm">数据加载</a> <div>1.首先你需要设置datagrid的onLoadSuccess $( '#dg' ).datagrid({onLoadSuccess :  function (data){      $( '#dg' ).datagrid( 'selectRow' ,3); }});   2.onL</div> </li> <li><a href="/article/3121.htm" title="jQuery用户数字打分评价效果" target="_blank">jQuery用户数字打分评价效果</a> <span class="text-muted">ini</span> <a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/html/1.htm">html</a><a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a> <div>效果体验:http://hovertree.com/texiao/jquery/5.htmHTML文件代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>jQuery用户数字打分评分代码 - HoverTree</</div> </li> <li><a href="/article/3248.htm" title="mybatis的paramType" target="_blank">mybatis的paramType</a> <span class="text-muted">kerryg</span> <a class="tag" taget="_blank" href="/search/DAO/1.htm">DAO</a><a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a> <div>MyBatis传多个参数: 1、采用#{0},#{1}获得参数:    Dao层函数方法:     public User selectUser(String name,String area); 对应的Mapper.xml    <select id="selectUser" result</div> </li> <li><a href="/article/3375.htm" title="centos 7安装mysql5.5" target="_blank">centos 7安装mysql5.5</a> <span class="text-muted">MrLee23</span> <a class="tag" taget="_blank" href="/search/centos/1.htm">centos</a> <div>首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安装mysql的步骤。   #列出所有被安装的rpm package rpm -qa | grep mariadb   #卸载 rpm -e mariadb-libs-5.</div> </li> <li><a href="/article/3502.htm" title="利用thrift来实现消息群发" target="_blank">利用thrift来实现消息群发</a> <span class="text-muted">qifeifei</span> <a class="tag" taget="_blank" href="/search/thrift/1.htm">thrift</a> <div>           Thrift项目一般用来做内部项目接偶用的,还有能跨不同语言的功能,非常方便,一般前端系统和后台server线上都是3个节点,然后前端通过获取client来访问后台server,那么如果是多太server,就是有一个负载均衡的方法,然后最后访问其中一个节点。那么换个思路,能不能发送给所有节点的server呢,如果能就</div> </li> <li><a href="/article/3629.htm" title="实现一个sizeof获取Java对象大小" target="_blank">实现一个sizeof获取Java对象大小</a> <span class="text-muted">teasp</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/HotSpot/1.htm">HotSpot</a><a class="tag" taget="_blank" href="/search/%E5%86%85%E5%AD%98/1.htm">内存</a><a class="tag" taget="_blank" href="/search/%E5%AF%B9%E8%B1%A1%E5%A4%A7%E5%B0%8F/1.htm">对象大小</a><a class="tag" taget="_blank" href="/search/sizeof/1.htm">sizeof</a> <div>   由于Java的设计者不想让程序员管理和了解内存的使用,我们想要知道一个对象在内存中的大小变得比较困难了。本文提供了可以获取对象的大小的方法,但是由于各个虚拟机在内存使用上可能存在不同,因此该方法不能在各虚拟机上都适用,而是仅在hotspot 32位虚拟机上,或者其它内存管理方式与hotspot 32位虚拟机相同的虚拟机上 适用。     </div> </li> <li><a href="/article/3756.htm" title="SVN错误及处理" target="_blank">SVN错误及处理</a> <span class="text-muted">xiangqian0505</span> <a class="tag" taget="_blank" href="/search/SVN%E6%8F%90%E4%BA%A4%E6%96%87%E4%BB%B6%E6%97%B6%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%BC%BA%E8%A1%8C%E5%85%B3%E9%97%AD/1.htm">SVN提交文件时服务器强行关闭</a> <div>在SVN服务控制台打开资源库“SVN无法读取current” ---摘自网络 写道 SVN无法读取current修复方法 Can't read file : End of file found 文件:repository/db/txn_current、repository/db/current   其中current记录当前最新版本号,txn_current记录版本库中版本</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>