nginx学习(1):编译、安装、启动
2015-06-15 11:31
253 查看
一、下载
从官网http://nginx.org/en/download.html 下载稳定版(目前最新稳定版是1.6.2)
二、解压
tar zxf nginx-1.6.2.tar.gz
cd nginx-1.6.2
三、配置
./configure --prefix=/opt/app/nginx/1.6.2 --user=cargo
注:prefix指定安装目录,user指定运行nginx的用户身份
通常第一次并不会顺利成功,如果出现:
./configure: error: the HTTP rewrite module requires the PCRE library.
表示当前机器上没有PCRE包,可以手动安装:
sudo yum -y install pcre-devel
再次运行./configure --prefix=/opt/app/nginx/1.6.2 --user=cargo,又有新的错误:
./configure: error: the HTTP gzip module requires the zlib library.
类似的,手动安装zlib包
sudo yum -y install zlib-devel
继续重复刚才的./configure命名,如果出现:
./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
继续手动安装open-ssl
yum -y install openssl openssl-devel
一切ok后,接下来可以编译了
四、编译
make install
注:需要gcc环境,如果没有安装gcc,请先安装gcc,方法 yum -y install gcc
顺利的话,会在/opt/app/nginx/1.6.2路径下生成很多文件
五、启动
cd /opt/app/nginx/1.6.2/sbin
./nginx
如果出现:
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
多半是80端口被占用
cd cd /opt/app/nginx/1.6.2/conf
vi nginx.conf
找到下面的内容:
server {
listen 80;
server_name localhost;
#charset koi8-r;
将80端口改成其它端口,比如7040(当然也可以把跟80冲突的进程给kill掉),然后再回到sbin目录,重复./nginx
正常的话,用ps -ef|grep nginx应该可以看到2个进程:
[cargo@vm-vmw1813-app sbin]$ ps -ef|grep nginx
cargo 4180 1 0 14:38 ? 00:00:00 nginx: master process ./nginx
cargo 4181 4180 0 14:38 ? 00:00:00 nginx: worker process
表示启动正常,可以用浏览器 访问 http://ip:7040/ 如果出现以下图片:
恭喜,安装成功!
六、卸载、停止服务
卸载只要把目录删除掉就行了,如果自己为了运维方便,做了其它启动的脚本,同步删除
停止服务,直接kill掉nginx进程最直接。
当然也可以 ./nginx -s stop
从官网http://nginx.org/en/download.html 下载稳定版(目前最新稳定版是1.6.2)
二、解压
tar zxf nginx-1.6.2.tar.gz
cd nginx-1.6.2
三、配置
./configure --prefix=/opt/app/nginx/1.6.2 --user=cargo
注:prefix指定安装目录,user指定运行nginx的用户身份
通常第一次并不会顺利成功,如果出现:
./configure: error: the HTTP rewrite module requires the PCRE library.
表示当前机器上没有PCRE包,可以手动安装:
sudo yum -y install pcre-devel
再次运行./configure --prefix=/opt/app/nginx/1.6.2 --user=cargo,又有新的错误:
./configure: error: the HTTP gzip module requires the zlib library.
类似的,手动安装zlib包
sudo yum -y install zlib-devel
继续重复刚才的./configure命名,如果出现:
./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
继续手动安装open-ssl
yum -y install openssl openssl-devel
一切ok后,接下来可以编译了
四、编译
make install
注:需要gcc环境,如果没有安装gcc,请先安装gcc,方法 yum -y install gcc
顺利的话,会在/opt/app/nginx/1.6.2路径下生成很多文件
五、启动
cd /opt/app/nginx/1.6.2/sbin
./nginx
如果出现:
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
多半是80端口被占用
cd cd /opt/app/nginx/1.6.2/conf
vi nginx.conf
找到下面的内容:
server {
listen 80;
server_name localhost;
#charset koi8-r;
将80端口改成其它端口,比如7040(当然也可以把跟80冲突的进程给kill掉),然后再回到sbin目录,重复./nginx
正常的话,用ps -ef|grep nginx应该可以看到2个进程:
[cargo@vm-vmw1813-app sbin]$ ps -ef|grep nginx
cargo 4180 1 0 14:38 ? 00:00:00 nginx: master process ./nginx
cargo 4181 4180 0 14:38 ? 00:00:00 nginx: worker process
表示启动正常,可以用浏览器 访问 http://ip:7040/ 如果出现以下图片:
恭喜,安装成功!
六、卸载、停止服务
卸载只要把目录删除掉就行了,如果自己为了运维方便,做了其它启动的脚本,同步删除
停止服务,直接kill掉nginx进程最直接。
当然也可以 ./nginx -s stop
相关文章推荐
- php-fpm nginx 框架重写规则
- Nginx中如何限制某个IP同一时间段的访问次数
- Nginx静态文件响应POST请求,提示405错误问题
- nginx 禁止某个IP访问
- Nginx Upload Module 上传模块测试例子
- ubuntu php 编译安装(nginx搭配)
- nginx平台初识(一)
- nginx平台初识(一)
- 低版本的Nginx支持PATHINFO的方法
- nginx
- Session Sticky About Nginx
- nginx 配置案例
- [转载] nginx的负载均衡
- Nginx 服务器安装及配置文件详解
- [亲测可用]ShopEx在Nginx上的的Rewrite伪静态规则
- Linux运维 第三阶段 (七) nginx(1)
- Nginx配置与应用详解
- nginx优化
- Nginx伪静态配置和常用Rewrite伪静态规则集锦
- nginx配置文件解析