文档库 最新最全的文档下载
当前位置:文档库 › Nginx安装学习使用详细记录

Nginx安装学习使用详细记录

Nginx安装学习使用详细记录
Nginx安装学习使用详细记录

前言:

选择Nginx的优点:

Nginx 可以在大多数 Unix like OS 上编译运行,并有 Windows 移植版。 Nginx 的1.4.0稳定版已经于2013年4月24日发布,一般情况下,对于新建站点,建议使用最新稳定版作为生产版本,已有站点的升级急迫性不高。Nginx 的源代码使用 2-clause BSD-like license。

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

在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。

1.1 执行安装

1.tar -xvf nginx-1.4.

2.tar.gz

2.cd nginx-1.4.2

3../configure --prefix=/usr/nginx --with-http_stub_status_module --with-debug --with

-http_realip_module --with-http_ssl_module

4.

5.

6.[root@localhost nginx-1.4.2]# make install

7.......

8.test-d \'/usr/nginx/logs\'|| mkdir -p \'/usr/nginx/logs\'

9.test-d \'/usr/nginx/logs\'|| mkdir -p \'/usr/nginx/logs\'

10.test-d \'/usr/nginx/html\'|| cp -R html \'/usr/nginx\'

11.test-d \'/usr/nginx/logs\'|| mkdir -p \'/usr/nginx/logs\'

1.2 查看进程数

进程数是与top出来的cpu数量是一样的。在/usr/local/nginx/conf/nginx.conf配置文件里面的worker_processes参数。

worker_processes指明了nginx要开启的进程数,据官方说法,一般开一个就够了,多开几个,可以减少机器io带来的影响。据实践表明,nginx的这个参数在一般情况下开4个或8个就可以了,再往上开的话优化不太大。据另一种说法是,nginx开启太多的进程,会影响主进程调度,所以占用的cpu会增高。

1.[root@lb-net-2 ~]# ps -eaf|grep nginx

2.root 2221 1382 0 18:06 pts/0 00:00:00 grep nginx

3.root 16260 1 0 Jun18 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

4.nobody 16261 16260 0 Jun18 ? 00:01:26 nginx: worker process

5.nobody 16262 16260 0 Jun18 ? 00:01:32 nginx: worker process

6.nobody 16263 16260 0 Jun18 ? 00:01:25 nginx: worker process

7.nobody 16264 16260 0 Jun18 ? 00:01:33 nginx: worker process

8.nobody 16265 16260 0 Jun18 ? 00:01:32 nginx: worker process

9.nobody 16266 16260 0 Jun18 ? 00:01:24 nginx: worker process

10.nobody 16267 16260 0 Jun18 ? 00:01:32 nginx: worker process

11.nobody 16268 16260 0 Jun18 ? 00:01:23 nginx: worker process

12.nobody 16269 16260 0 Jun18 ? 00:01:32 nginx: worker process

13.nobody 16270 16260 0 Jun18 ? 00:01:26 nginx: worker process

14.nobody 16271 16260 0 Jun18 ? 00:01:32 nginx: worker process

15.nobody 16272 16260 0 Jun18 ? 00:01:25 nginx: worker process

16.nobody 16273 16260 0 Jun18 ? 00:01:26 nginx: worker process

17.nobody 16274 16260 0 Jun18 ? 00:01:32 nginx: worker process

18.nobody 16275 16260 0 Jun18 ? 00:01:32 nginx: worker process

19.nobody 16276 16260 0 Jun18 ? 00:01:33 nginx: worker process

20.nobody 16277 16260 0 Jun18 ? 00:01:24 nginx: worker process

21.nobody 16278 16260 0 Jun18 ? 00:01:24 nginx: worker process

22.nobody 16279 16260 0 Jun18 ? 00:01:30 nginx: worker process

23.nobody 16280 16260 0 Jun18 ? 00:01:24 nginx: worker process

24.nobody 16281 16260 0 Jun18 ? 00:01:32 nginx: worker process

25.nobody 16282 16260 0 Jun18 ? 00:01:32 nginx: worker process

26.nobody 16283 16260 0 Jun18 ? 00:01:25 nginx: worker process

27.nobody 16284 16260 0 Jun18 ? 00:01:26 nginx: worker process

2 配置文件

2.1 Nginx反向代理实践

省过

2.2 Nginx Rewrite重新定向

使用nginx做重新定向。

nginx参考网址:https://www.wendangku.net/doc/7b2263637.html,/s/blog_97688f8e0100zws5.html

语法规则: location [=|~|~*|^~] /uri/ { … }

= 开头表示精确匹配

^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可。nginx不对url做编码,因此请求为/static/20%/aa,可以被规则^~ /static/ /aa匹配到(注意是空格)。

~ 开头表示区分大小写的正则匹配

~* 开头表示不区分大小写的正则匹配

!~和!~*分别为区分大小写不匹配及不区分大小写不匹配的正则

/ 通用匹配,任何请求都会匹配到。

多个location配置的情况下匹配顺序为(参考资料而来,还未实际验证,试试就知道了,不必拘泥,仅供参考):

首先匹配 =,其次匹配^~, 其次是按文件中顺序的正则匹配,最后是交给 / 通用匹配。当有匹配成功时候,停止匹配,按当前匹配规则处理请求。

例子,有如下匹配规则:

location = / {

#规则A

}

location = /login {

#规则B

}

location ^~ /static/ {

#规则C

}

location ~ \.(gif|jpg|png|js|css)$ {

#规则D

}

location ~* \.png$ {

#规则E

}

location !~ \.xhtml$ {

#规则F

}

location !~* \.xhtml$ {

#规则G

}

location / {

#规则H

}

那么产生的效果如下:

访问根目录/,比如http://localhost/ 将匹配规则A

访问 http://localhost/login 将匹配规则B,http://localhost/register 则匹配规则H 访问 http://localhost/static/a.html 将匹配规则C

访问 http://localhost/a.gif, http://localhost/b.jpg 将匹配规则D和规则E,但是规则D顺序优先,规则E不起作用,而 http://localhost/static/c.png 则优先匹配到规则C

访问 http://localhost/a.PNG 则匹配规则E,而不会匹配规则D,因为规则E不区分大小写。

访问 http://localhost/a.xhtml 不会匹配规则F和规则G,http://localhost/a.XHTML

不会匹配规则G,因为不区分大小写。规则F,规则G属于排除法,符合匹配规则但是不会匹配到,所以想想看实际应用中哪里会用到。

访问 http://localhost/category/id/1111 则最终匹配到规则H,因为以上规则都不匹配,这个时候应该是nginx转发请求给后端应用服务器,比如FastCGI(php),tomcat(jsp),nginx作为方向代理服务器存在。

所以实际使用中,个人觉得至少有三个匹配规则定义,如下:

#直接匹配网站根,通过域名访问网站首页比较频繁,使用这个会加速处理,官网如是说。#这里是直接转发给后端应用服务器了,也可以是一个静态首页

# 第一个必选规则

location = / {

proxy_pass http://tomcat:8080/index

}

# 第二个必选规则是处理静态文件请求,这是nginx作为http服务器的强项

# 有两种配置模式,目录匹配或后缀匹配,任选其一或搭配使用

location ^~ /static/ {

root /webroot/static/;

}

location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {

root /webroot/res/;

}

#第三个规则就是通用规则,用来转发动态请求到后端应用服务器#非静态文件请求就默认是动态请求,自己根据实际把握

#毕竟目前的一些框架的流行,带.php,.jsp后缀的情况很少了location / {

proxy_pass http://tomcat:8080/

}

2.3 ReWrite语法

last –基本上都用这个Flag。

break –中止Rewirte,不在继续匹配

redirect –返回临时重定向的HTTP状态302

permanent –返回永久重定向的HTTP状态301

1、下面是可以用来判断的表达式:

-f和!-f用来判断是否存在文件

-d和!-d用来判断是否存在目录

-e和!-e用来判断是否存在文件或目录

-x和!-x用来判断文件是否可执行

2、下面是可以用作判断的全局变量

例:http://localhost:88/test1/test2/test.php

$host:localhost

$server_port:88

$request_uri:http://localhost:88/test1/test2/test.php $document_uri:/test1/test2/test.php

$document_root:D:\nginx/html

$request_filename:D:\nginx/html/test1/test2/test.php

2.4 Redirect语法

server {

listen 80;

server_name https://www.wendangku.net/doc/7b2263637.html,;

index index.html index.php;

root html;

if ($http_host !~ “^star\.igrow\.cn$" {

rewrite ^(.*) https://www.wendangku.net/doc/7b2263637.html,$1 redirect;

}

}

2.5 防盗链

location ~* \.(gif|jpg|swf)$ {

valid_referers none blocked https://www.wendangku.net/doc/7b2263637.html, https://www.wendangku.net/doc/7b2263637.html,; if ($invalid_referer) {

rewrite ^/ http://$host/logo.png;

}

}

2.6 根据文件类型设置过期时间

location ~* \.(js|css|jpg|jpeg|gif|png|swf)$ {

if (-f $request_filename) {

expires 1h;

break;

}

}

2.7 禁止访问某个目录

location ~* \.(txt|doc)${

root /data/www/wwwroot/linuxtone/test;

deny all;

}

一些可用的全局变量:

$args

$content_length

$content_type

$document_root

$document_uri

$host

$http_user_agent

$http_cookie

$limit_rate

$request_body_file

$request_method

$remote_addr

$remote_port

$remote_user

$request_filename

$request_uri

$query_string

$scheme

$server_protocol

$server_addr

$server_name

$server_port

$uri

2.8 Nginx静态文件(css,js,jpg等等web静态资源)

vim /usr/local/nginx/conf/nginx.conf

server {

listen 80;

server_name localhost;

open_file_cache max=10000 inactive=60s;

location /group1/M00 {

root /data/fastdfs/data;

ngx_fastdfs_module;

}

location /css {

root plocc_static;

include gzip.conf;

}

location /common {

root plocc_static;

include gzip.conf;

}

2.9 nginx 转发工程的日志文件

去nginx.conf配置文件里面去看访问日志,如下:

vim nginx.conf

location ~* ^/mobileWeb/.*$ {

include deny.conf;

proxy_pass http://mobilewebbackend;

include proxy.conf;

error_log logs/mobileweb_error.log error; access_log logs/mobileweb_access.log main;

include gzip.conf;

}

再去logs目录查看日志文件,如下:

[root@xx logs]# ll /usr/local/nginx/logs/mobileweb* -rw-r--r--. 1 root root 10946 7月 18 10:36

/usr/local/nginx/logs/mobileweb_access.log

-rw-r--r--. 1 root root 1628 7月 18 10:36

/usr/local/nginx/logs/mobileweb_error.log

3 添加启动服务

1.[root@localhost nginx]# cat /etc/init.d/nginx

2.#!/bin/bash

3.#chkconfig:2345 70 70

4.#description:nginx

5.BIN=/usr/nginx/sbin/nginx

6.function d_start {

7. $BIN ||echo-n \"nginx is running\"

8.}

9.

10.function d_stop {

11. $BIN -s stop ||echo-n \"nginx is not running\"

12.}

13.

14.function d_reload {

15. $BIN -s reload ||echo-n \"nginx reload failed\"

16.}

17.

18.case $1 in

19.start)

20.echo start nginx

21. d_start

22.;;

23.stop)

24.echo stop nginx

25. d_stop

26.;;

27.reload)

28.echo reload nginx

29. d_reload

30.;;

31.restart)

32.echo restart nginx

33. d_stop

34.echo sleep 5s

35.sleep 5

36. d_start

37.;;

38.*)

39.echo \"Usage: nginx [start | stop |reload |restart]\"

40.;;

41.

42.esac

43.exit 0

启动:service nginx start;

4 制作证书Key。

4.1.首先要生成服务器端的私钥(key文件):

openssl genrsa -des3 -out server.key 2048

Enter pass phrase for server.key:gongsilong0617

4.2.用server.key生成一个证书:

openssl req -new -key server.key -out server.csr

pass phrase: gongsilong0617

[root@localhost ssl]# openssl req -new -key server.key -out server.csr

Enter pass phrase for server.key:

You are about to be asked to enter information that will be incorporated into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [GB]:cn

State or Province Name (full name) [Berkshire]:shanghai

Locality Name (eg, city) [Newbury]:shanghai

Organization Name (eg, company) [My Company Ltd]:gongsilong

Organizational Unit Name (eg, section) []:business

Common Name (eg, your name or your server's hostname) []:ops

Email Address []:mch@https://www.wendangku.net/doc/7b2263637.html,

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:gongsilong0617

An optional company name []:gongsilong

[root@localhost ssl]#

4.3. 对客户端也作同样的命令生成key及csr文件

openssl genrsa -des3 -out client.key 2048

pass phrase: plclient0618

[root@localhost client]# openssl req -new -key client.key -out client.csr

Enter pass phrase for client.key:

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [GB]:cn

State or Province Name (full name) [Berkshire]:shanghai

Locality Name (eg, city) [Newbury]:shanghai

Organization Name (eg, company) [My Company Ltd]:gongsilong

Organizational Unit Name (eg, section) []:business

Common Name (eg, your name or your server's hostname) []:ops

Email Address []:mch@https://www.wendangku.net/doc/7b2263637.html,

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:plclient0618

An optional company name []:gongsilong

4.4 生成的CSR证书文件必须有CA的签名才可形成证书.这里制作自己的CA 这时生成一个KEY文件ca.key 和根证书ca.crt

pass phrase: gongsilong0617

[root@localhost ssl]# openssl req -new -x509 -nodes -keyout ca.key -out ca.crt Generating a 1024 bit RSA private key

.......++++++

................++++++

writing new private key to 'ca.key'

Enter PEM pass phrase:

Verifying - Enter PEM pass phrase:

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [GB]:cn

State or Province Name (full name) [Berkshire]:shanghai

Locality Name (eg, city) [Newbury]:

writing new private key to 'ca.key'Organization Name (eg, company) [My Company Ltd]: [root@localhost ssl]# openssl req -new -x509 -keyout ca.key -out ca.crt Generating a 1024 bit RSA private key

..............++++++ ..................................................++++++

writing new private key to 'ca.key'

Enter PEM pass phrase:

Verifying - Enter PEM pass phrase:

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [GB]:cn

State or Province Name (full name) [Berkshire]:shanghai

Locality Name (eg, city) [Newbury]:shanghai

Organization Name (eg, company) [My Company Ltd]:gongsilong

Organizational Unit Name (eg, section) []:business

Common Name (eg, your name or your server's hostname) []:ops

Email Address []:mch@https://www.wendangku.net/doc/7b2263637.html,

[root@localhost ssl]#

[root@localhost ssl]# mch@https://www.wendangku.net/doc/7b2263637.html,

-bash: mch@https://www.wendangku.net/doc/7b2263637.html,: command not found

[root@localhost ssl]#

签署证书准备工作:

[root@mail ssl]# vim /etc/pki/tls/https://www.wendangku.net/doc/7b2263637.html,f

#dir = ../../CA //修改如下

dir = /etc/pki/plocc/CA

touch /etc/pki/plocc/CA/{index.txt,serial}

[root@localhost ssl]# ll /etc/pki/plocc/CA/

总计 0

-rw-r--r-- 1 root root 0 06-18 10:47 index.txt

-rw-r--r-- 1 root root 0 06-18 10:47 serial

[root@localhost ssl]# echo 01 > /etc/pki/plocc/CA/serial

[root@localhost ssl]# mkdir /etc/pki/plocc/CA/newcerts

4.5 用生成的CA的证书(ca.crt)为刚才生成的server.csr,client.csr文件签名

pass phrase:gongsilong0617

openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key

[root@localhost ssl]# openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key

Using configuration from /etc/pki/tls/https://www.wendangku.net/doc/7b2263637.html,f

Enter pass phrase for ca.key:

Check that the request matches the signature

Signature ok

Certificate Details:

Serial Number: 1 (0x1)

Validity

Not Before: Jun 18 04:04:09 2014 GMT

Not After : Jun 18 04:04:09 2015 GMT

Subject:

countryName = cn

stateOrProvinceName = shanghai

organizationName = baolong

organizationalUnitName = business

commonName = ops

emailAddress = mch@https://www.wendangku.net/doc/7b2263637.html,

X509v3 extensions:

X509v3 Basic Constraints:

CA:FALSE

Netscape Comment:

OpenSSL Generated Certificate

X509v3 Subject Key Identifier:

52:6A:D9:56:CB:2B:DA:E3:9A:18:CC:FE:4D:A1:8C:21:86:55:D5:11

X509v3 Authority Key Identifier:

keyid:4E:F5:29:7F:6B:AD:11:EF:FC:44:CC:76:1D:B0:B9:F7:4B:9D:CB: 93

Certificate is to be certified until Jun 18 04:04:09 2015 GMT (365 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[root@localhost ssl]#

[root@localhost ssl]# openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key

Using configuration from /etc/pki/tls/https://www.wendangku.net/doc/7b2263637.html,f

Enter pass phrase for ca.key:

Check that the request matches the signature

Signature ok

Certificate Details:

Serial Number: 2 (0x2)

Validity

Not Before: Jun 18 04:10:40 2014 GMT

Not After : Jun 18 04:10:40 2015 GMT

Subject:

countryName = cn

stateOrProvinceName = shanghai

organizationName = baolong

organizationalUnitName = business

commonName = ops

emailAddress = mch@https://www.wendangku.net/doc/7b2263637.html,

X509v3 extensions:

X509v3 Basic Constraints:

CA:FALSE

Netscape Comment:

OpenSSL Generated Certificate

X509v3 Subject Key Identifier:

E2:64:97:DC:A6:2B:85:53:5F:6C:5C:8D:1F:EB:59:C8:2C:66:C5:10

X509v3 Authority Key Identifier:

keyid:4E:F5:29:7F:6B:AD:11:EF:FC:44:CC:76:1D:B0:B9:F7:4B:9D:CB: 93

Certificate is to be certified until Jun 18 04:10:40 2015 GMT (365 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[root@localhost ssl]#

[PS]:附带功能:

另外,这个certificate是BASE64形式的,要转成PKCS12才能装到IE,/NETSCAPE上.转换如下:

双击安装就行

openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12这个是ISO 需要的证书格式

openssl x509 -in client.crt -out client.cer

这个是android 需要的证书格式。

[root@mail ssl]# openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx

Enter pass phrase for client.key: //客户端私钥密码

Enter Export Password: //pfx文件导入要求的密码

Verifying - Enter Export Password:

[root@localhost conf]# service nginx stop

stop nginx

Enter PEM pass phrase:

phrase is too short, needs to be at least 4 chars

Enter PEM pass phrase:

phrase is too short, needs to be at least 4 chars

Enter PEM pass phrase:

nginx启动SSL默认不输入密码

如果nginx配置了SSL,在每次启动nginx的时候都会需要你手动输入证书的密码,如果不想输入,可以

cp server.key server.key.orig

openssl rsa -in server.key.orig -out server.key

这样启动nginx的时候就不需要输入密码了。

[root@localhost ssl]# cp server.key server.key.orig

[root@localhost ssl]# openssl rsa -in server.key.orig -out server.key

Enter pass phrase for server.key.orig:

unable to load Private Key

20487:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:325:

20487:error:0906A065:PEM routines:PEM_do_header:bad decrypt:pem_lib.c:425:

[root@localhost ssl]#

这里奇怪,一开始通不过,但是过了15分钟后,在运行一遍,输入密码,又通过了,如下所示:

[root@localhost ssl]# openssl rsa -in server.key.orig -out server.key

Enter pass phrase for server.key.orig:

writing RSA key

[root@localhost ssl]#

当然也可以保留密码,改用expect的方式,这个可以参考expect自动登录SSH的方法,下次有时间再整理贴上来

5 静态文件地址映射 nginx

location = userWeb/userCenter/findConsultList.htm {

rewrite ^.*$ https://www.wendangku.net/doc/7b2263637.html,/xx/xx/findConsultList.htm; }

# add by tim begin ...

location ~* ^/svn/(.*) {

rewrite ^.*$ https://192.123.11.12/$1;

}

# add by tim end ..

Windows下Nginx的安装与配置

Windows下Nginx的安装与配置 Windows下Nginx的安装与配置 Nginx ("engine x") 是一款高性能的,轻量级的HTTP Web服务器和反向代理服务器及电子邮件IMAP/POP3/SMTP代理服务器。 Nginx是由俄罗斯的程序设计师Igor Sysoev 所开发,为俄罗斯访问量第二的Rambler.ru 站点开发的,它已经在该站点运行超过四年多时间了,Igor 将源代码以类BSD许可证的形式发布。 自Nginx 发布四年来,Nginx 已经因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。Nginx 超越Apache的高性能和稳定性,使得国内使用Nginx 作为Web 服务器的网站也越来越多。 目前国内各大门户网站已经部署了Nginx,如新浪、网易、腾讯等;新近发现Nginx 技术在国内日趋火热,越来越多的网站开始应用部署Nginx。 一、首先去官网下载nginx1.0.11的Windows版本,官网下载: https://www.wendangku.net/doc/7b2263637.html,/download/nginx-1.0.11.zip 下载到软件包后,解压nginx-nginx1.0.11.zip 包到你喜欢的根目录,并将目录名改为nginx。 然后,执行下列操作: cd nginx start nginx 这样,nginx 服务就启动了。打开任务管理器,查看nginx.exe 进程,有二个进程会显示,占用系统资源,那是相当的少。然后再打开浏览器,输入http://127.0.0.1/就可以看到nginx 的欢迎页面了,非常友好 nginx -s stop // 停止nginx nginx -s reload // 重新加载配置文件 nginx -s quit // 退出nginx 二、接下来就是配置nginx的conf文件了。下面是我的配置: #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;

2019年nginx安装手册

Nginx安装手册 1nginx安装环境 nginx是C语言开发,建议在linux上运行,本教程使用作为安装环境。 ?gcc 安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++ ?PCRE PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。yum install -y pcre pcre-devel 注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。 ?zlib zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。 yum install -y zlib zlib-devel ?openssl OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。 nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux 安装openssl库。 yum install -y openssl openssl-devel 2编译安装 将拷贝至linux服务器。 解压: tar -zxvf --help查询详细参数(参考本教程附录部分:nginx编译参数) 参数设置如下: ./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/ \ --lock-path=/var/lock/ \ --error-log-path=/var/log/nginx/ \

nginx设置rewrite规则

Nginx 设置rewrite规则 Windows下环境为wamp ,在wamp 环境下,设置rewite规则时,很是简单,只需要打开Apache配置中的rewrite规则,项目中使用rewrite规则时只需创建.htaccess文件,在文件中编写规则,Apache会自动进行解析,但是在linux下则有些不一样。 Linux下环境若是lamp,则和wamp下是相同的,但当环境为lnmp时,需要注意进行如下配置方法: 根据所安装的环境情况,如果环境是lnmp集成环境,在配置rewrite规则时,因为集成环境,在安装完毕后,在安装的目录/usr/local/nginx/conf下,会生成一个文件“wordparss”,这个文件中是专门用于写rewrite规则所用,你可以在这个文件中书写rewrite规则,nginx 的rewrite规则与Apache的规则基本是相同的,只是在文件中书写的方法不同,wordpaess 问件中默认是有一个规则的,如: 利用location加载访问路径,“/”,指代由访问路径的根目录开始, 用if对加载的路径$request_filename 进行验证: 1 、-f 和!-f 用来判断文件是否存在 2、-d 和!-d 用来判断目录是否存在 3 、-e 和!-e 用来判断文件或目录是否存在 4、-x 和!-x 用来判断文件是否可执行 Flag标记: 1、last 相当于Apache里的[L]标记,表示完成rewrite 2、break 终止匹配, 不再匹配后面的规则 3、redirect 返回302临时重定向地址栏会显示跳转后的地址 4、permanent 返回301永久重定向地址栏会显示跳转后的地址 因为在lnmp集成环境下要配置虚拟域名是可以进行自动生成的,生成后会在/usr/local/nginx/conf/vhost 下生成一个以虚拟域名的名字的文件,如:lin_hp.its.conf,而所对应的rewrite规则最好在与域名相对应的配置文件中进行配置,这样不会说,如果有多个域名时,他们所对应的rewrite规则不同,在公共的wordpress文件中配置引起冲突,所配置的方法与在wprdpress文件中是相同的,如:

在centos上搭建nginx图片服务器(包含上传模块)

安装Nginx 和相关的插件 (Image Filter Module & Upload Module & Upload Progress Module) (1) install essential sys library $ yum -y install gcc-c++ $ yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gd gd-devel (2)install nginx & related module plugin $ wget https://https://www.wendangku.net/doc/7b2263637.html,/masterzen/nginx-upload-progress-module/archive/v0.9.1.tar.gz $ wget https://https://www.wendangku.net/doc/7b2263637.html,/vkholodkov/nginx-upload-module/archive/2.2.0.tar.gz $ wget https://www.wendangku.net/doc/7b2263637.html,/download/nginx-1.3.8.tar.gz $ tar zxvf *.tar.gz $ cd /nginx-1.3.8/conf (3)configure nginx.conf $ vi nginx.conf #user root; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"';

nginx配置解析详解(一)

nginx配置解析详解(一) 现在针对nginx源码分析的blog和文章已经很多了,之前我也看过不少,大家的分析都很不错。太多重复的内容就不写了,主要想针对在我分析代码和查阅blog的过程中,发现的一些比较晦涩或者某些细节有待展开讨论的地方,给出我的自己理解和看法,希望跟大家交流和学习。 使用的nginx版本是nginx-1.0.6,我最开始看的代码是0.7.62,新的版本在功能和稳定性上做了很多的工作。在分析的时候,我尽量简单明了,不太重要的地方一带而过,具体地大家可以去读代码。相对复杂或者晦涩的地方,将详细展开。 首先我们从配置文件开始,下面的分析是建立在网友对nginx的配置文件结构有大概熟悉为前提,这样才可以很好的理解代码。这里有必要提醒一点:原始代码目录中 ngx_modules这个结构,是找不到它的定义和初始化,要看到它,你必须执行configure,make,在原来的代码目录下会出现一个objs文件夹,里面的3个文件ngx_auto_config.h,ngx_auto_headers.h,ngx_modules.c,需要在建source insight工程时也包含进去,这样有利于我们把握整个代码结构。有意思的是,nginx的configure文件是作者手工写的,里面有许多管理代码工程的方法,有时间的话,也是值得学习下的。 1.ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle); 配置文件的解析相关的处理主要在ngx_init_cycle函数中被调用。既然如此,我们就先说说ngx_init_cycle函数吧。 它需要一个参数类型为ngx_cycle_t *,返回值也是一个ngx_cycle_t*,与此同时我们注意到参数名为old_cycle,那么这个函数的作用是啥呢?很明显是由old得到一个new。其中ngx_cycle_t的结构保存一些全局的配置和信息。 这个函数具体作用将在reconfig(重读配置文件)的时候得到体现,可以理解为old_cycle 是当前正在使用的配置信息,当配置文件做了某些修改之后,ngx_init_cycle通过old_cycle 中的一些数据,对new_cycle进行一些设置,在经过进一步的配置解析之后,就可以得到一个new cycle。 2.char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) 当我们使用sourceinsight查看这个函数的调用情况时,会发现调用它的地方很多。其实,入口点就在ngx_init_cycle中对ngx_conf_parse调用,后面的所有的调用可以看作是在此之后的递归调用。为什么会是这个样子呢?原因在于nginx是一边读取配置信息,一边解析执行相关的处理,具体一点讲,就是“读一行,执行一行”,一行的定义在这里是指以分号或者是“{”和“}”等结尾的一行,例如:我们解析到http {},我们就调用针对httpblock的处理,在处理的时候我们又会碰到server {},自然就会调用server block的处理。。。以此类推!。

手把手教你开发Nginx模块

手把手教你开发Nginx模块 前面的哪些话 关于Nginx模块开发的博客资料,网上很多,很多。但是,每篇博客都只提要点,无法"step by step"照着做,对于初次接触Nginx开发的同学,只能像只盲目的蚂蚁瞎燥急!该篇文章没有太多技术深度,只是一步一步说明白Nginx模块的开发过程。 开发环境搭建 工欲善其事,必先利其器。个人推荐Eclipse CDT 作为IDE,原因很简单,代码提示与补全功能很全,完胜Codeblock这类...相信与否,试过就知道。 在ubuntu下搭建开发环境: 安装GCC编译器 apt-get install build-essential 安装pcre/openssl/zlib开发库 apt-get install libpcre3-dev apt-get install libssl-dev apt-get install libzip-dev 必需安装nginx核心模块依赖的pcre,openssl,zilib开发库 安装JRE/Eclipse CDT apt-get install openjdk-8-jre wget http://ftp.yz.yamagata-u.ac.jp/pub/eclipse//technology/epp/downloads/release/neon/R/eclipse-cpp-neon-R-linux-gtk-x86_64.tar.gz && tzr -xzvf eclipse-cpp-neon-R-linux-gtk-x86_64.tar.gz 下载nginx源码 wget https://www.wendangku.net/doc/7b2263637.html,/download/nginx-1.10.1.tar.gz && tar -xzvf nginx-1.10.1.tar.gz 配置CDT Build Environment 添加变量,值Nginx src下各模块路径,用冒号分隔,例如: /root/Workspace/nginx-1.10.1/src/core:/root/Workspace/nginx-1.10.1/src/event:/root/Workspace/nginx-1.10.1/src/http:/root/Workspace/nginx-1.10.1/src/mail:/root/Workspace/n ginx-1.10.1/src/stream:/root/Workspace/nginx-1.10.1/src/os/unix 添加环境变量,创建C项目时自动作为-I选项 image image Nginx模块编译流程 Nginx使用configure脚本分析环境,自动生成objs结果。哪么configure如何编译第三方模块?答案是--add-module指定第三方模块目录,并将目录存为$ngx_addon_dir环境变量。执行$ngx_addon_dir/config脚本,读取模块配置。在config中的环境变量分为2种:小写的本地环境变量,大写的全局环境变量。例如: ngx_addon_name=ngx_http_mytest_module

nginx虚拟主机和文件服务器的配置

Nginx文件服务器和虚拟主机的配置 https://www.wendangku.net/doc/7b2263637.html,的配置文件: 1.游戏服务器: server { listen 80; server_name https://www.wendangku.net/doc/7b2263637.html,; index index.html index.htm index.php; root /data/web/fc/game3w/releases1/public; location ~ .*\.php$ { include fcgi.conf; fastcgi_pass 127.0.0.1:10080; fastcgi_index index.php; expires off; } access_log /data/logs/https://www.wendangku.net/doc/7b2263637.html,.log access; } 2.客户端的配置: server { listen 80; server_name https://www.wendangku.net/doc/7b2263637.html,; index index.html index.htm index.php; root /data/web/fc/resource; charset utf-8; #expires 2h; location ~* .svn$ { return 404; } location ~ .*\.swf$ { expires 365d; } location ~ .*\.css$ { expires 365d; } location ~ .*\.xml$ { expires 365d;

} location ~ .*\.js$ { expires 365d; } location ~ .*\.jpg$ { expires 365d; } location ~ .*\.gif$ { expires 365d; } location ~ .*\.png$ { expires 365d; } location ~ .*\.mp3$ { expires 365d; } location ~ .*\.game$ { expires 365d; } location ~ .*\.lib$ { expires 365d; } access_log off; } 3.文件服务器的配置: server { listen 9000; server_name 192.168.26.8; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; index index.html index.htm index.php; root /data/server/trunk/bin/logs/; allow all; } }

Nginx系列讲解

Nginx系列 一信号与配置 一、Nginx与信号 Nginx支持平滑重启,相比于Apache,修改了配置文件后可以不需要先停止程序,再重新启动。 1、启动 nginx –c nginx.conf 其中,-c nginx.conf可以省略不写。如果省略,则默认加载安装目录下的conf子目录中的nginx.conf。 2、停止 停止的方式有很多种,kill时传入不同的信号来结束或者平滑重启。Nginx的进程号记录在Pid文件中,Pid文件的位置可以在conf/nginx.conf中找到。如下图: 当然,也可以根据 ps –ef | grep nginx 来查找Nginx的进程号。我们可以通过kill命令来结束Nginx。 从容停止Nginx: kill –QUIT Nginx进程ID 或 kill – QUIT /usr/local/nginx/logs/nginx.pid 快速停止Nginx: kill –TERM Nginx进程ID 或

kill – TERM /usr/local/nginx/logs/nginx.pid 或 kill –INT Nginx进程ID 或 kill – INT /usr/local/nginx/logs/nginx.pid 强制停止Nginx: kill –9 Nginx进程ID 或 kill -9 /usr/local/nginx/logs/nginx.pid 或 pkill -9 nginx 3、重启 如果修改了Nginx的配置文件,想要重启Nginx。同样可以使用kill命令来传递信号。不过,在此之前,我强烈建议先检查并测试配置文件是否正确。 测试配置文件: nginx –t –c conf/nginx.conf 若提示unknow directive *** in conf/nginx.conf:55. Configuration file conf/nginx.conf test failed,则证明在第55行的***是非法的,需要修改。 若提示the configuration file conf/nginx.conf syntax is ok. Configuration file conf/nginx.conf test is successful,则证明配置文件测试通过,可以重启Nginx了。 平滑重启Nginx: kill –HUP Nginx进程ID 或

Nginx与PHP(FastCGI)的安装、配置与优化

Nginx与PHP(FastCGI)的安装、配置与优化 FastCGI的介绍和工作原理 首先简单的介绍下FastCGI: FastCGI是语言无关的、可伸缩结构的CGI开放扩展,其主要行为是将CGI解释器进行保持在内存中并因此获得较高的性能。众所周知,CGI解释器的反复加载是CGI性能低下的主要原因,如果CGI解释器保持在内存中并接受FastCGI进程管理器调度,则可以提供良好的性能、伸缩性、Fail-Over特性等。 FastCGI的工作原理是: (1)FastCGI进程管理器自身初始化,启动多个CGI解释器进程(多个php-cgi进程)并等待来自Web Server的连接。在文本中,采用PHP-FPM进程管理器启动多个php-cgi FastCGI进程。启动php-cgi FastCGI进程时,可以配置以TCP和UNIX套接字两种方式启动。 (2)当客户端请求达到Web服务器(Nginx)时,Web服务器将请求采用TCP协议或UNIX 套接字方式转发到FastCGI主进程,FastCGI主进程选择并连接到一个CGI解释器(子进程)。Web服务器将CGI环境变量和标准输入发送到FastCGI子进程php-cgi。 (3)FastCGI子进程完成处理后将标准输出和错误信息从同一连接返回Web服务器(Nginx)。当FastCGI子进程关闭连接时,请求便告知处理完成。FastCGI子进程接着等待并处理来自FastCGI进程管理的下一个连接。而在一般的普通CGI模式中,php-cgi在此便退出了。 PHP-FPM PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,可以在 https://www.wendangku.net/doc/7b2263637.html,/downloads.php下载得到.PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

window下nginx配置

原来一直以为nginx只能在Linux下搭建,最近查了些资料才恍然大悟,Windows下其实也可以跑nginx。当你的网站访问量越来越高的时候,一台服务器已经没有办法承受流量压力,后果可想而知,怎么办呢?那就增加几台服务器来做负载吧。但当下的硬件设施又是贵得离谱,比如F5,所以这种情况下,免费的nginx成了我们不错的选择,nginx目前好多门户网站与大访问量的网站都在使用做为HTTP服务器,所以nginx是相当优秀的…… 实验环境:(2台服务器) 第一台: 系统:Win2003 nginx:nginx/Windows-0.8.32 IP:192.168.0.51 环境:本地 第二台: 系统:Win2003 IP:192.168.0.52 环境:远程 说明: 本次测试,软件nginx放在本地(192.168.0.51),也就是说放在域名绑定的那台服务器,这台服务器的IIS不能使用80端口,因为等一下nginx软件要使用80这个端口。(为了方便,我将本机的hosts文件添加了我要测试的域名192.168.0.51 https://www.wendangku.net/doc/7b2263637.html,) 下载nginx的地址如下: nginx下载:https://www.wendangku.net/doc/7b2263637.html,/ 下载解压到C:\,把目录名改成nginx 一切准备就绪,开始实验: No.1: 在本地(192.168.0.51)这台服务器IIS创建一个网站,使用端口为808,如下图:

IIS 网站绑定设置图 No.2: 在远程192.168.0.52的IIS创建一个网站,使用端口为80,如下图: No.3: 好了,以上已经设置好两台服务器的IIS了,下面配置nginx软件来实现网站负载均衡,打开如下文件: C:\nginx\conf\nginx.conf 1、找到内容server { 在它的上面加入如下内容:

linux下Nginx+tomcat整合的安装与配置

linux下Nginx+tomcat整合的安装与配置 目的:搭建Nginx与tomcat整合,用Nginx代替apache 步骤: 一、安装Tomcat和JDK 1、上传apache-tomcat-6.0.18.tar.gz和jdk-6u12-linux-i586.bin至/usr/local 2、执行如下命令安装tomcat: 查看 打印? 1. 2.#cd /usr/local 3.#tar zxvf apache-tomcat-6.0.18.tar.gz 解压完成后将apache-tomcat-6.0.18重命名为tomcat 3、执行如下命令安装JDK: 查看 打印? 1. 2.#./jdk-6u12-linux-i586.bin 4、配置环境变量: 编辑/etc下的profile文件,加上如下内容: 查看 打印? 1. 2.JAVA_HOME="/usr/local/jdk1.6.0_12" 3.CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib" 4.PATH=".:$PATH:$JAVA_HOME/bin " 5. 6.CATALINA_HOME="/usr/local/tomcat" 7.export JAVA_HOME CATALINA_HOME 5、启动tomcat并输入http://localhost:8080,如果看到猫的页面即tomcat和jdk安装成功 6、新建文件目录/home/www为网站存放目录,设置server.xml文件,在Host name="localhost"处将appBase=的指向路径改为/home/www/web

Windows下编译Nginx并添加模块

Windows下编译Nginx并添加模块 一.准备工作 1.环境安装 1.安装vs2010或vs2013等vs工具。 2.安装ActivePerl,安装完成后,将其安装路径加入到PATH环境变量。 3.安装MinGW,下载mingw-get-setup.exe,安装完成后,将其安装路径加入到PATH环境变量。(记得安装的时候装上msys,不懂就全勾了) 4.安装nasm,安装完成后,将其安装路径加入到PATH环境变量。 2.下载编译nginx源码文件 1.nginx源码:nginx-1.1 2.2 2.pcre:pcre-8.40 3.zlib:zlib-1.2.11 4.openssl:openssl-1.0.2l 3.下载添加模块文件 1.文件上传模块: nginx-upload-module 2.rtmp模块:nginx-rtmp-module 3.文件上传进度条模块:nginx-upload-progress-module 二.编译并添加模块 1.将上述7个压缩包文件解压至文件夹msys文件目录下,如C:\MinGW\msys\1.0\home\$UESRNAME\。 2.找到msys.bat的路径并双击msys.bat,运行。如下图所示

3.打开msys.bat后如下所示 右击上方编辑栏,选择编辑,粘贴,可进行粘贴复制功能。 4.cd 至nginx源码路径,并在源码路径下执行下面语句: auto/configure --with-cc=cl --builddir=objs --prefix= \ --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid \ --http-log-path=logs/access.log --error-log-path=logs/error.log \ --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp \ --http-proxy-temp-path=temp/proxy_temp \ --http-fastcgi-temp-path=temp/fastcgi_temp \ --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=../pcre-8.40 \ --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2l \ --with-select_module --with-http_ssl_module \ --with-http_sub_module \ --add-module=../nginx-upload-module-2.255 \ --add-module=../nginx-upload-progress-module-master \ --add-module=../nginx-rtmp-module-master \ 其中pcre,zlib,openssl的语句需根据版本号的不同进行改变,最后增加的模块也需更具实际情况进行相应的改变,步骤4操作如下图所示:

nginx负载均衡master配置文件nginx.conf

#user nobody; worker_processes auto; #error_log logs/error.log; error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; worker_rlimit_nofile 100000; events { use epoll; worker_connections 204800; } http { ## 用户的IP 地址$binary_remote_addr 作为Key,每个IP 地址最多有50 个并发连接 ## 你想开几千个连接刷死我?超过50 个连接,直接返回503 错误给你,根本不处理你的请求了 limit_conn_zone $binary_remote_addr zone=TotalConnLimitZone:10m ; #limit_conn TotalConnLimitZone 50; limit_conn TotalConnLimitZone 500; limit_conn_log_level notice; ## 用户的IP 地址$binary_remote_addr 作为Key,每个IP 地址每分钟处理50 个请求## 你想用程序每秒几百次的刷我,没戏,再快了就不处理了,直接返回503 错误给你 #limit_req_zone $binary_remote_addr zone=ConnLimitZone:10m rate=200r/m; limit_req_zone $binary_remote_addr zone=ConnLimitZone:10m rate=2000r/m; limit_req_log_level notice; #include mime.types; #default_type application/octet-stream; #access_log logs/access.log main; #server_tokens off; #sendfile on; #tcp_nopush on; #keepalive_timeout 0; #keepalive_timeout 65; server_tokens off; include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" '

NGinx分布式部署测试实例图解

https://www.wendangku.net/doc/7b2263637.html,+Mvc+NGinx+IIS分布式部署和负载平衡实例图解 目的:在IIS中创建四个相同的网站,浏览器访问同一个地址,通过NGinx转到不同的IIS 网站。 测试条件: Windows 7 X64旗舰版+Visual Studio 2017专业版 1、创建https://www.wendangku.net/doc/7b2263637.html, +Mvc WebApplication 在VS运行后的页面效果如下:

2、发布网站 3、IIS中部署四个网站 创建三个应用程序池,端口分别为: 8001、8002、8003,8004分别对应四个网站。 为区分三个网站,把Index.cshtml文件中的“Nginx测试程序”这行字分别改为:Nginx测试程序--------1 Nginx测试程序--------2 Nginx测试程序--------3 Nginx测试程序--------4 如下图: 部署四个网站后,打开页面效果如下:

到此,说明四个网站部署后单独访问都没有问题。下面开始部署NGInx的负载平衡。

4、NGInx的安装 4.1、下载nginx-1.1 5.1 下载后解压到D:\nginx文件夹,解压后的文件夹如下: 4.2、修改配置文件nginx.conf nginx.conf文件位于D:\nginx\conf目录下,nginx.conf默认内容如下。用记事本打开文件,nginx.conf文件的内容如下: #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '

Nginx-1.0.15负载均衡安装配置

nginx-1.0.15负载均衡安装配置 OS:ubuntu 1、取得软件 pcre-8.30.zip nginx-1.0.15.tar.gz apt-get install gcclibpcre*zlib 2、安装rewrite的支持库pcre unzip pcre-8.30.zip cd pcre-8.30 ./configure make make install 3、配置nginx.conf cat /usr/local/nginx/conf/nginx.conf | grep -Ev '(#|^$)' worker_processes 1; events { worker_connections 1024; } http { includemime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream https://www.wendangku.net/doc/7b2263637.html, { server 10.0.0.252:8080; server 10.0.0.253:8080; server 10.0.0.105:8080; } server { listen 80; server_name https://www.wendangku.net/doc/7b2263637.html,; location ~ ^/$ { rewrite ^/(.*) /jboss/ break; proxy_pass https://www.wendangku.net/doc/7b2263637.html,; } } }

4、启动nginx服务 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Nginx的介绍和使用

1.什么是Nginx Nginx(发音同engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,最初供俄国大型的入口网站及搜寻引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页伺服器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、腾讯,另外知名的微网志Plurk 也使用nginx。 优点: (1)Nginx 可以在大多数 Unix like OS 上编译运行,并有 Windows 移植版。 Nginx 的1.2.6稳定版已经于2012年12月11日发布,[1]1.3.10开发版已经于2012年12月25日发布,如果新建站点,建议使用最新稳定版作为生产版本,已有站点升级急迫性不高。Nginx 的源代码使用 2-clause BSD-like license。 (2)Nginx 是一个很强大的高性能Web和反向代理服务器,它具有很多非常优越的特性: 在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。 (3)Nginx作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP代理服务器对外进行服务。Nginx采用C进行编写,不论是系统资源开销还是CPU使用效率都比 Perlbal 要好很多。 作为邮件代理服务器:Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last. fm 描述了成功并且美妙的使用经验。 (4)Nginx 是一个安装非常的简单,配置文件非常简洁(还能够支持perl语法),Bugs非常少的服务器:Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够不间断服务的情况下进行软件版本的升级。 2.下载和安装Nginx Nginx的官方网站是https://www.wendangku.net/doc/7b2263637.html,/cn/,英文主页为https://www.wendangku.net/doc/7b2263637.html,,从这里可以获得Nginx 的最新版本信息。Nginx有三个版本:稳定版、开发版和历史稳定版。开发版更新较快,包含最新的功能和bug的修复,但同时也可能会遇到新的bug,开发版一旦更新稳定下来,就会被加入稳定版分支中。然而有些新功能不一定会被加到旧的稳定版中去。稳定版本更新较慢,但是bug较少,可以作为生产环境的首选,因此通常建议使用稳定版。历史稳定版本为以往稳定版本的汇总,不包含最新的功能。 这里选择当前的稳定版本nginx-0.7.65作为介绍对象,开始介绍编译安装。在安装Nginx 之前,确保系统已经安装了gcc、 openssl-devel、 pcre-devel和zlib-devel软件库。Linux开发库是在安装系统时通过手动选择安装的,gcc、 openssl-devel、zlib-devel三个

Nginx+PHP+MySQL详细配置(图)

Nginx是一个高性能的HTTP和反向代理服务器,同时还是IMAP/POP3/SMTP代理服务器,该程序由俄罗斯Rambler.ru 站点开发,Nginx因为性能稳定、低系统资源消耗而闻名,近几年Nginx在国内已经成炙热化状态,比如像腾讯、网易、51CTO、迅雷、当当网、51、人人网等诸多大型网站都已经使用Nginx来做Web服务器,所以我们要学会运用Nginx还是非常有必要的,下面我们一起来看一下Nginx是如何在Linux平台上搭建的 安装前首先使用yum命令安装、升级所需的程序库 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel ssse2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers 一、安装MySQLssss 目前web服务器已经很少有跑静态页面的,如果要跑动态网站那当然就离不开数据库,虽然在以前文章中有写MySQL是怎么安装的,但是感觉好久没装MySQL,现在只把步骤贴出来,就不做过多的讲解了 #useradd mysql #tar zxvf mysql-5.0.40.tar.gz #cd mysql-5.0.40 #./configure --prefix=/usr/local/mysql #make && make install #/usr/local/mysql/bin/mysql_install_db --user=mysql //初始化MySQL数据库 #chown -R mysql /usr/local/mysql/var #/usr/local/mysql/bin/mysqld_safe & //启动MySQL #/usr/local/mysql/bin/mysqladmin -u root password 123456 //设置MySQL密码 #cp support-files/https://www.wendangku.net/doc/7b2263637.html,f /etc/https://www.wendangku.net/doc/7b2263637.html,f #echo "/usr/local/mysql/bin/mysqld_safe &" >>/etc/rc.local

nginx配置方案

WEB服务器安装方案 平台搭建环境: CentOS5.2 32/x86_64 GNU/Linux (32/64操作系统均通过,推荐使用64位操作系统) 一、系统安装 1. 系统分区建议 /boot 256M swap 2GB / 20GB /usr 40GB (用于安装软件) /data 剩余所有空间. 二、编译安装基本环境 1. 安装准备 1.1 系统约定 软件源代码包存放位置 /usr/local/src 源码包编译安装位置(prefix) /usr/local/software_ name 脚本以及维护程序存放位置 /usr/local/sbin MySQL 数据库位置 /data/mysql/(可按情况设置) 网站根目录/data/www/htdocs(可按情况设置) 网站日志根目录/data/www/logs(可按情况设置) Nginx运行账户www 1.2创建网站账号及相关存放目录 /usr/sbin/groupadd www /usr/sbin/useradd -g www www mkdir -p /data/www/html mkdir -p /data/www/log chown -R www:www /data/www/html chown -R www:www /data/www/log 1.3系统环境部署及调整 # tail -n100 /var/log/messages (检查有无系统级错误信息) # dmesg (检查硬件设备是否有错误信息) # ifconfig(检查网卡设置是否正确) # ping 192.168.95.1 (检查网络是否正常) install_software_name.sh //存放编译参数脚本习惯将所有编译脚本存放在install_software_name.sh便于升级和更新软件. 1.4定时校正服务器时钟,定时与中国国家授时中心授时服务器同步 #crontab -e

相关文档