想要Linux下安装Nginx作为WEB服务器,要先准备些必要的库和工具,通常必须安装的是 PERC和Openssl库。
前提:
1.安装PCRE库(Nginx的rewrite模块和HTTP核心模块会用到PCRE正则表达式语法)
yum install pcre pcre-devel
2.安装OpenSSL库(若服务器提供安全网页(https://)时,会用到OpenSSL库)
yum install openssl openssl-devel
注意:带-devel的库和不带-devel的库的区别,在我之前的文章里有介绍,这里不再赘述。
yanlei:linux 中 devel包 和 非devel包的区别zhuanlan.zhihu.com正题:
1.使用 wget 或 curl 命令下载nginx
2.使用 tar 命令解压nginx
3.进入解压目录 使用 ./configure --help 查看nginx的可配置项 (也可通过nginx官网查看,地址:http://nginx.org/en/docs/configure.html)
注意:--with- 开头的配置项是没有安装的配置,该参数表示安装此配置
--without- 开头的配置项是已经安装的配置,该参数表示卸载此配置
4.使用 ./configure 预编译nginx、
注意:一定要写成 ./configure ,而不是configure,运行其它二进制的程序也一样,直接写 configure,linux 系统会去 PATH 里寻找有没有叫 configure 的,而只有 /bin, /sbin, /usr/bin,/usr/sbin 等在 PATH 里,你的当前目录通常不在 PATH 里,所以写成 configure 是会找不到命令的,要用 ./configure 告诉系统说,就在当前目录找 (更多内容请查看https://www.runoob.com/linux/linux-shell.html)
例如:./configure --prefix=/usr/local/nginx --with-http_ssl_module
预编译完成截图:
![63f4c94cd84a0a145deee884294a2800.png](https://img-blog.csdnimg.cn/img_convert/63f4c94cd84a0a145deee884294a2800.png)
5.使用 make 命令编译nginx
注意:执行该命令后会在nginx命令下生成objs文件夹,里面是编译产生的中间文件
![4378a0a1f5c2c1d9a6be4238f8273b86.png](https://img-blog.csdnimg.cn/img_convert/4378a0a1f5c2c1d9a6be4238f8273b86.png)
6.使用 make install 命令安装nginx
注意:里面的conf目录是复制的解压后源文件里的conf目录
![b27544bdada324c3678a7f6a0c7fab6e.png](https://img-blog.csdnimg.cn/img_convert/b27544bdada324c3678a7f6a0c7fab6e.png)
7.使用 nginx 命令行
![3eca5d9d6a4c9dd4cd0a744532d77e54.png](https://img-blog.csdnimg.cn/img_convert/3eca5d9d6a4c9dd4cd0a744532d77e54.png)