Centos 64位安装nginx-1.6.2

前端之家收集整理的这篇文章主要介绍了Centos 64位安装nginx-1.6.2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

linux系统为Centos 64位

第一步:从http://Nginx.org/download/上下载相应的版本(或者wget http://Nginx.org/download/Nginx-1.5.9.tar.gz直接在Linux上用命令下载)

第二步:解压tar -zxvf Nginx-1.5.9.tar.gz

第三步:设置一下配置信息./configure --prefix=/usr/local/Nginx ,或者不执行此步,直接默认配置

第四步:

make编译 (make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件

make install安装 (make install是把这些编译出来的可执行文件和库文件复制到合适的地方)

在配置信息的时候,也就是在第三步,出现了一下错误

Centos 64位安装nginx-1.6.2

错误为:./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题
yum -y install pcre-devel

还有可能出现:

Centos 64位安装nginx-1.6.2

安装zlib-devel解决问题
yum -y install zlib-devel

还有可能出现:

错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option,or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with Nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解决办法:

yum -y install openssl openssl-devel

安装后在linux下启动和关闭Nginx

启动操作

/usr/Nginx/sbin/Nginx(/usr/Nginx/sbin/Nginx-t查看配置信息是否正确)

web界面:http://192.168.189.136:80/

停止操作
停止操作是通过向Nginx进程发送信号(什么是信号请参阅linux文章)来进行的
步骤1:查询Nginx主进程号
ps-ef|grepNginx
在进程列表里面找master进程,它的编号就是主进程号了。
步骤2:发送信号
从容停止Nginx
kill-QUIT主进程号
快速停止Nginx
kill-TERM主进程号
强制停止Nginx
pkill-9Nginx

另外,若在Nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在Nginx的logs目录下。有了pid文件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:
kill-信号类型'/usr/Nginx/logs/Nginx.pid'

平滑重启
如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx发送信号,平滑重启。
平滑重启命令:
kill-HUP住进称号或进程号文件路径

或者使用

/usr/Nginx/sbin/Nginx-sreload

利用Nginx配置Web Server的负载均衡,需要修改的地方有:

a) 在http标签下,配置upstream属性,如:

upstream mysvr {
#weigth参数表示权值,权值越高被分配到的几率越大
server 192.168.189.136:8080 weight=5;
server 192.168.189.137:8080 weight=1;
server 192.168.189.138:8080 weight=6;
}

其中,weight是可选项;若不配置weight,则默认所有的Web Server具有相同的权重。

b) 在http标签下的server标签中,做适当的修改,如:

server {
listen 83;
server_name localhost;

location / {
root /root;
index index.jsp;
proxy_pass http://mysvr;
proxy_set_header Host $host:83;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

……
}

其中需要说明的是,server_name和listen分别设置的是用户访问的地址和端口;proxy_pass指定转向的服务器列表(在upstream中定义);proxy_set_header Host设置跳转的http报文中的地址为proxy_pass中指定的地址,同时可以在此处指定端口号,若不指定,则默认会跳到80端口。

本例服务器采用tomcat

输入如下网址测试:

http://192.168.189.136:80/examples/

http://192.168.189.136:8080/examples/

http://192.168.189.137:8080/examples/

http://192.168.189.138:8080/examples/

猜你在找的CentOS相关文章