Linux操作系统安装nginxs
来源:互联网 发布:淘宝霸王条款 编辑:程序博客网 时间:2024/06/05 18:03
什么是Nginx?
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apache 服务器不错的替代品.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。
Nginx 作为 负载均衡 服务器:
Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP 代理服务器对外进行服务。 Nginx 采用 C 进行编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好很多。作为邮件代理服务器:
Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验。Nginx 是一个安装非常简单,配置文件非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。 你还能够不间断服务的情况下进行软件版本的升级。
下载
cd /user/local wget http://nginx.org/download/nginx-1.8.0.tar.gz
安装依赖项
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
环境配置
<span style="font-size:14px;">cd nginx-1.8.0 ./configure </span>安装
make && make install
启动查看
cd /usr/local/nginx/sbin ./nginxps -aux|grep nginx
关闭重启
./nginx -s stop ./nginx -s reload
查看状态
./nginx -t
如何设置成开机启动
<span style="font-size:14px;">cd /etc/init.d touch nginx 这是创建文件(当文件不存在的时候)</span>新建完之后编辑
<span style="font-size:14px;">vim /etc/init.d/nginx </span>
进入编辑文件之后 按 i 然后就可以插入了,复制下面代码拷贝进去
<span style="font-size:14px;">#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL </span>
然后按 Esc 按钮退出编辑 并且 输入 :wq 保存并退出
赋予执行权限
<span style="font-size:14px;">chmod +x /etc/init.d/nginx </span>添加服务
<span style="font-size:14px;">chkconfig --add nginx </span>设置成开机启动
<span style="font-size:14px;">chkconfig --level 35 nginx on </span>查看是否设置成功
<span style="font-size:14px;">chkconfig --list | grep nginx </span>
第二种 自己下载安装
Nginx的安装
模块依赖性Nginx需要依赖下面3个包
1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )
3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )
Nginx包下载: http://nginx.org/en/download.html
依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.
图解教程
第一步: 下载安装所需包
openssl-fips-2.0.2.tar.gz
zlib-1.2.7.tar.gz
pcre-8.21.tar.gz
nginx-1.2.6.tar.gz
第二步:依次安装openssl-fips-2.0.2.tar.gz, zlib-1.2.7.tar.gz, pcre-8.21.tar.gz, nginx-1.2.6.tar.gz
1.安装openssl-fips-2.0.2.tar.gz
[root@localhost mrms]# tar -zxvf openssl-fips-2.0.2.tar.gz [root@localhost mrms]# cd openssl-fips-2.0.2[root@localhost openssl-fips-2.0.2]# ./config [root@localhost openssl-fips-2.0.2]# make[root@localhost openssl-fips-2.0.2]# make install
2.安装zlib-1.2.7.tar.gz
[root@localhost mrms]# tar -zxvf zlib-1.2.7.tar.gz[root@localhost mrms]# cd zlib-1.2.7[root@localhost zlib-1.2.7]# ./configure [root@localhost zlib-1.2.7]# make[root@localhost zlib-1.2.7]# make install
3.安装pcre-8.21.tar.gz
[root@localhost mrms]# tar -zxvf pcre-8.21.tar.gz[root@localhost mrms]# cd pcre-8.21[root@localhost pcre-8.21]# ./configure [root@localhost pcre-8.21]# make[root@localhost pcre-8.21]# make install
4.安装 nginx-1.2.6.tar.gz
[root@localhost mrms]# tar -zxvf nginx-1.2.6.tar.gz [root@localhost mrms]# cd nginx-1.2.6[root@localhost nginx-1.2.6]# ./configure --with-pcre=../pcre-8.21 --with-zlib=../zlib-1.2.7 --with-openssl=../openssl-fips-2.0.2[root@localhost nginx-1.2.6]# make[root@localhost nginx-1.2.6]# make install
至此Nginx的安装完成!
第三步:检测是否安装成功
[root@localhost nginx-1.2.6]# cd /usr/local/nginx/sbin[root@localhost sbin]# ./nginx -t
出现如下所示提示,表示安装成功
启动nginx
[root@localhost sbin]# ./nginx
查看端口
[root@localhost sbin]# netstat -ntlp
结果如下
- Linux操作系统安装nginxs
- 硬盘安装linux操作系统
- 硬盘安装Linux操作系统
- linux操作系统安装命令
- [1]安装linux操作系统
- 安装Linux操作系统
- 远程安装Linux操作系统
- Linux操作系统安装ArcSDE10
- linux操作系统安装输入法
- Linux操作系统的安装
- 定制安装linux操作系统
- Linux 操作系统安装篇
- 操作系统--Linux的安装
- 安装Linux操作系统
- Linux操作系统安装方法
- 远程安装Linux操作系统
- Linux操作系统的安装
- linux操作系统仿真安装
- java多线程
- 通讯录-静态实现
- Objective-C 关于静态方法与实例方法
- 将流转换成字符串
- android 如何创建快捷小图标
- Linux操作系统安装nginxs
- 选择云存储服务商的6条安全红线
- Problem E: Balance (华中农业大学预赛)
- android开发笔记之多媒体—小图片的加载
- 连接MySQL错误:Can't connect to MySQL server (10060)
- 数据库设计三大范式
- 纯手工编写可执行程序
- Palette(调色板)
- 第7周 C语言程序设计(新2版) 练习2-3 字符串转换成等价整型值