[nginx学习之道]linux的nginx安装
准备:首先要安装下一些gcc库用于编译 和一些nginx的扩展lib包:
[root@localhost nginx-1.8.]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
1.首先去nginx的官网选择要安装的nginx版本并复制其下载的url,并在linux用wget进行下载,tar解压和进入安装的源码目录:
[root@localhost ~]# wget -c http://nginx.org/download/nginx-1.8.1.tar.gz && tar zxvf ./nginx-1.8.1.tar.gz && cd ./nginx-1.8.1
然后根据自己的情况以及./configure --help命令查看下一些主要的配置选项:然后进行配置make三部中的一部./configure
[root@localhost nginx-1.8.]# ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/ \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/cilent/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
遇到的一些问题:
问题1:(没有安装gcc)
checking for OS
+ Linux 3.10.-.el7.x86_64 x86_64
checking for C compiler ... not found ./configure: error: C compiler cc is not found
解决:
[root@localhost nginx-1.8.]# yum -y install gcc gcc-c++ autoconf automake
问题2:(没有安装一些库,因为在./configure中我用到了 例如ssl等等这个根据自己的实际需求进行安装)
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决:
[root@localhost nginx-1.8.]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
好接下来用make 去尝试编译下检测下是否有问题(很多时候我们习惯用 make && make install直接进编译安装,那是因为我在下面已经做了测试没有问题在搭建生产环境的时候为了节约时间才这样做的)
[root@localhost nginx-1.8.]# make
如果没有出现error的字眼就说明make检测没有问题。这时候运行make install就会很少有错误。
[root@localhost nginx-1.8.]# make install
Ok到此已经安装完成:
这个时候我尝试启动下:(根据我上面的./configure 的配置sbin-path是在/usr/local/nginx/sbin/nginx 我的默认配置文件在/usr/local/nginx/conf/nginx.conf)
[root@localhost nginx-1.8.]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] getpwnam("nginx") failed
上面错误提示我没有nginx这个用户和主:两种方式1.将nginx.conf中的user和group修改成已经存在的其他用户。不建议用root;2.创建我指定的用户和组命令如下:
[root@localhost nginx-1.8.]# /usr/sbin/groupadd -f nginx
[root@localhost nginx-1.8.]# /usr/sbin/useradd -g nginx nginx
在尝试启动还有错误提示:
[root@localhost nginx-1.8.]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] mkdir() "/var/tmp/nginx/cilent/" failed (: No such file or directory)
[root@localhost nginx-1.8.]# mkdir /var/tmp/nginx/cilent
mkdir: 无法创建目录"/var/tmp/nginx/cilent": 没有那个文件或目录
解决办法创建:
[root@localhost nginx-1.8.]# mkdir -p /var/tmp/nginx/cilent
然后启动:
[root@localhost nginx-1.8.]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
OK没有报错:确认是否启动可以用ps -ef | grep nginx去检索下(这里有个技巧,一般nginx的启动都是这种形式,如果你的linux服务器上有很多的nginx.conf这个命令可以帮你更快的锁定现在用的配置文件。)
[root@localhost nginx-1.8.1]# ps -ef | grep nginx
root 42388 1 0 15:58 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx 42389 42388 0 15:58 ? 00:00:00 nginx: worker process
root 42391 10803 0 15:58 pts/1 00:00:00 grep --color=auto nginx
解释下上面的参数 master process 是主进程的意思 pid是 42388 下面的是子进程。
ok这个进程我们其实还可以去一个文件中看到,对就是我们在./configure 的配置的pid文件:cat下这个文件会看到里面已经有了对应的pid号:
[root@localhost nginx-1.8.1]# cat /var/run/nginx/nginx.pid
42388
这个pid的作用可以让我们在操作nginx和方便:比如说重启 或者停止服务(kill) 或者平滑重启。
从容停止nginx:
kill - QUIT `/var/run/nginx/nginx.pid`
快速停止:
kill - TERM `/var/run/nginx/nginx.pid`
强制停止:
kill - `/var/run/nginx/nginx.pid`
以上都可以直接指定pid号例如
kill - QUIT
[nginx学习之道]linux的nginx安装的更多相关文章
- Nginx学习系列二Linux下Nginx实现负载均衡
关于在本地虚拟机(VMware 14)下安装Linux同时安装Nginx,请参考Nginx学习系列之搭建环境 1.启动Nginx 在Nginx安装成功的前提下,启动Nginx 已root模式登陆(权限 ...
- Linux学习心得之 Linux下ant安装与使用
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Linux学习心得之 Linux下ant安装与使用 1. 前言2. ant安装3. 简单的a ...
- nginx学习(一):基本安装
转载自http://summervast.blog.51cto.com/690507/385511 注意:可能因版本不同,个别指令不起作用,需要注意版本灵活安装,我在安装时也遇到过此问题 开始学习ng ...
- 【转】Nginx 学习笔记(十一)nginx下安装配置naxsi waf防火墙(附完整编译、配置)
原文地址:http://f2ex.cn/nginx-installed-configuration-naxsi-waf/ Naxsi 是第三方 nginx 模块 ,它和 Modsecurity 都是开 ...
- Nginx学习笔记(三)--- Nginx实现反向代理和配置负载均衡
1.反向代理 2.Nginx反向代理流程图 3.安装多个tomcat 3.1把tomcat的压缩包传到Linux上 3.2 解压tomcat 3.3 给压缩好的tomcat改个名字用来区分一下 3.4 ...
- Nginx学习笔记(三) Nginx基本数据结构
Nginx基本数据结构 话说学习一种编程语言,例如C语言,我们首先学的也是数据结构,这是以后开发程序的关键.为了更好更方便的开发Nginx,Nginx自己实现了很多适合nginx的数据结构. Ngin ...
- Nginx学习总结(5)——Nginx基本配置备忘
Nginx 配置 在了解具体的Nginx配置项之前我们需要对于Nginx配置文件的构成有所概念,一般来说,Nginx配置文件会由如下几个部分构成: # 全局块 ... # events块 events ...
- 学习鸟哥linux私房菜--安装centos5.6(u盘安装,中文乱码)
题头为"学习鸟哥Linux私房菜"的内容,均为博主在看鸟哥的Linux私房菜第三版的学习经历收获.以下正文: 鸟哥第一部分讲Linux规则与安装,看到第四章正式开始讲实际安装,于是 ...
- Nginx学习(1)--- 介绍与安装
1.基础介绍 常用功能 1.HTTP服务 动静分离.WEB缓存.虚拟主机设置.URL Rewrite 2.负载均衡 3.反向代理 4.正向代理 5.邮件服务器 优点 高扩展.高可用.支持高并发.低资源 ...
随机推荐
- 第九章 JQUI
一.什么是插件 ①是遵循一定接口规范编写的程序 ②是原有系统平台功能的扩展和补充 ③只能运行在规定的系统平台下,而不能单独运行 注:由于jQuery插件是基于jQuery脚本库的扩展,所以所有jQue ...
- 片元着色器(Fragment Shader)被称为像素着色器(Pixel Shader),但
片元着色器(Fragment Shader)被称为像素着色器(Pixel Shader),但片元着色器是一个更合适的名字, 因为此时的片元并不是一个真正意义上的像素.
- inverse
首先术语inverse 被翻译为反转的意思.inverse 制定了关联关系中的方向. 当set的inverse属性默认情况下,hibernate会按照持久化对象的属性变化来同步更新数据库. 得到两条s ...
- BZOJ2748[HAOI2012]音量调节
Description 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量.在演出开始之前,他已经做好了一个列表,里面写着在每首歌开始之前他想要改 ...
- WPScan用法
kali下集成的WPScan用法 1.刺探基础信息:wpscan --url http://www.example.com 2.猜解后台用户名wpscan --url http://www.examp ...
- VS一直停留在“正在还原nuget程序包”
VS一直停留在“正在还原nuget程序包” 在开发何问起收藏夹的时候,准备在WinFrom中加入网页浏览器,于是下载了一个CEFSharp的源码,生成解决方案的时候,一直提示“正在还原nuget程序包 ...
- spring独立事务分析
最近在ssm框架的项目中需要用到独立事务的实现,找了半天,搜集了以下理论知识为实现做准备.事务管理器为datasource (1)Spring在transactiondefinition接口中规定了7 ...
- [CareerCup] 6.6 Toggle Lockers 切换锁的状态
6.6 There are 100 closed lockers in a hallway. A man begins by opening all 100 lockers. Next, he clo ...
- EventToCommand
EventToCommand 在WPF中,并不是所有控件都有Command,例如TextBox,那么当文本改变,我们需要处理一些逻辑,这些逻辑在ViewModel 中,没有Command如何绑定呢?这 ...
- scala速成记录1
选择 Learning Scala这本书,两百多页,足够薄. 安装 http://www.scala-lang.org/ 下载Binary的版本.bin里边有所有操作系统下运行的可以运行的交互式s ...