Nginx安装
来源:互联网 发布:ubuntu安装 中文语言包 编辑:程序博客网 时间:2024/06/12 23:00
1.Nginx安装环境
nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境。
gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc。yum install gcc-c++
PCRE
PCRE是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip。
yum install -y zlib zlib-devel
openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel2.
2.编译安装
将nginx-1.8.0.tar.gz拷贝至linux服务器。备注: 可以使用vsftp 服务器 或者 SSH Secure Shell Client,SecureCRT 等客户端。第一步:解压
[root@localhost ~]#tar -zxvf nginx-1.8.0.tar.gz
[root@localhost ~]# ll
total 896
-rw-------. 1 root root 1385 Mar 6 06:51 anaconda-ks.cfg
-rw-r--r--. 1 root root 49565 Mar 6 06:51 install.log
-rw-r--r--. 1 root root 10033 Mar 6 06:49 install.log.syslog
drwxr-xr-x. 9 1001 1001 4096 Mar 6 11:45 nginx-1.8.0//解压成功
-rw-r--r--. 1 root root 832104 Jan 25 11:57 nginx-1.8.0.tar.gz //上传成功
-rw-r--r--. 1 root root 0 Mar 6 11:11 off
[root@localhost ~]# cd nginx-1.8.0
3.编译
[root@localhost nginx-1.8.0]# ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
4.安装[root@localhost nginx-1.8.0] #make
[root@localhost nginx-1.8.0] #make install
[root@localhost nginx-1.8.0]# cd /usr/local/
[root@localhost local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 2 root root 4096 Sep 23 2011 include
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
drwxr-xr-x. 5 root root 4096 Mar 6 11:45 nginx//出现此文件夹 nginx安装成功
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 5 root root 4096 Mar 6 06:44 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
5.查看nginx目录结构
[root@localhost local]# cd /usr/local/nginx
[root@localhost nginx]# ll
total 12
drwxr-xr-x. 2 root root 4096 Mar 7 05:10 conf //存放nginx配置文件 ,nginx.conf
drwxr-xr-x. 2 root root 4096 Mar 6 11:45 html
drwxr-xr-x. 2 root root 4096 Mar 6 11:45 sbin //可执行文件
6.nginx操作命令
[root@localhost nginx]# cd /sbin //启动nginx
[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps aux|grep nginx //查询nginx进程
[root@localhost sbin]# ps aux|grep nginx
root 1728 0.0 0.0 24316 656 ? Ss 11:03 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf
ftpuser 1731 0.0 0.0 24744 1240 ? S 11:03 0:00 nginx: worker process
root 2483 0.0 0.0 103260 836 pts/0 S+ 11:36 0:00 grep nginx
[root@localhost sbin]#
./nginx -s stop //第一种方式: 杀掉nginx进程
./nginx -s quit//第二种方式:待进程处理完毕再停止
//重启nginx
[root@localhost sbin]# ./nginx -s quit
[root@localhost sbin]# ./nginx
//修改nginx配置文件之后命令:
[root@localhost sbin]# ./nginx -s quit
[root@localhost sbin]# ./nginx -s reload //重新加载nginx配置文件
7.修改nginx.conf 配置文件--服务器防火墙
[root@localhost sbin]# vim /etc/sysconfig/iptables
* 红色框内是需要添加的代码 , 添加完毕后 按键盘 "ESC" 退出, 输入 ":wq" 进行保存。
[root@localhost sbin]# service iptables start//重启生效
[root@localhost sbin]#/etc/init.d/iptables status //查看防火墙状态 是否有nginx 80端口
在安装过程出现错误:
nginx: [emerg] mkdir() “/var/temp/nginx/client” failed (2: No such file or directory)
解决方法:mkdir -p /var/temp/nginx/client 因为这个在安装过程中可能目录没有原因。
[root@localhost sbin]# mkdir -p /var/temp/nginx/client
[root@localhost sbin]# .nginx
8.测试访问
- nginx笔记:nginx安装
- Nginx-----源码安装nginx
- 【nginx】nginx的安装
- 安装Nginx
- nginx安装
- 安装 nginx
- 安装nginx
- 安装 Nginx
- nginx安装
- Nginx安装
- 安装Nginx
- 安装nginx
- nginx安装
- 安装nginx
- Nginx安装
- nginx安装
- nginx安装
- nginx 安装
- [iBET Malaysia]Sports Book Rebate 0.35% Bonus
- 消息摘要加密算法MD
- CentOS(Linux) 下vi编辑器用法大全
- iOS学习笔记之-使用UITouch来根据手指位置移动图片
- 完美学术ppt
- Nginx安装
- js学习记录3
- react 实现手机端首页无缝轮播
- 64位win7系统下cocos2d-x3.x的环境配置(自学笔记)
- 合并两个排序链表
- 使用moy快速开发后台管理系统(一)
- 图像切割,使用ROI
- sizeof系列——struct class union
- 消息摘要加密算法SHA