CentOs7.3 编译安装 Nginx 1.9.9

前端之家收集整理的这篇文章主要介绍了CentOs7.3 编译安装 Nginx 1.9.9前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOs7.3 编译安装 Nginx 1.9.9

安装

安装依赖

$ yum install -y  gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel

下载并解压

$ cd /opt/
$ wget http://Nginx.org/download/Nginx-1.9.9.tar.gz
$ tar zxvf Nginx-1.9.9.tar.gz

编译

编译时候可以指定编译参数,参考文章尾部:常用编译选项

$ cd Nginx-1.9.9
$ ./configure

安装

$ make
$ make && make install

默认安装在/usr/locale/Nginx

里面有四个目录:

常用命令

正确性检查

每次修改Nginx配置文件后都要进行检查

$ /usr/local/Nginx/sbin/Nginx -t
Nginx: configuration file /usr/local/Nginx/conf/Nginx.conf test is successful

启动

$ /usr/local/Nginx/sbin/Nginx

如果不能访问,检查防火墙并关闭防火墙

centos 6.x 关闭 iptables

$ service iptables status # 查询防火墙状态命令
$ service iptables stop # 关闭命令

centos 7.x 关闭firewall

$ ssystemctl status  firewalld.service # 查看状态
$ systemctl stop firewalld.service # 停止firewall

浏览器输入本机IP ,看到如下内容证明安装成功

Welcome to Nginx!

If you see this page,the Nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to Nginx.org.
Commercial support is available at Nginx.com.

Thank you for using Nginx.

停止

$ /usr/local/Nginx/sbin/Nginx -s stop

重启

$ /usr/local/Nginx/sbin/Nginx -s reload

常用编译选项

./configure \
--prefix=/home/Nginx \
--sbin-path=/usr/sbin/Nginx \
--user=Nginx \
--group=Nginx \
--conf-path=/etc/Nginx/Nginx.conf \
--error-log-path=/home/log/Nginx/error.log \
--http-log-path=/home/log/Nginx/access.log \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/home/run/Nginx.pid \
--with-pcre=/home/software/pcre-8.35 \
--with-zlib=/home/software/zlib-1.2.8 \
--with-openssl=/home/software/openssl-1.0.1i

选项说明

--prefix=/home/Nginx \ Nginx安装的根路径,所有其它路径都要依赖该选项
--sbin-path=/usr/sbin/Nginx \ Nginx的可执行文件的路径(Nginx)
--user=Nginx \ worker进程运行的用户
--group=Nginx \ worker进程运行的组
--conf-path=/etc/Nginx/Nginx.conf \  指向配置文件Nginx.conf)
--error-log-path=/var/log/Nginx/error.log \ 指向错误日志目录
--http-log-path=/var/log/Nginx/access.log \  设置主请求的HTTP服务器的日志文件名称
--with-http_ssl_module \  使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
--with-http_gzip_static_module \  启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
--with-http_stub_status_module \  启用ngx_http_stub_status_module支持获取Nginx自上次启动以来的工作状态)
--with-http_realip_module \  启用ngx_http_realip_module支持(这个模块允许从请求标头更改客户端的IP地址值,默认为关)
--pid-path=/var/run/Nginx.pid \  指向pid文件Nginx.pid)

设置PCRE库的源码路径,如果已通过yum方式安装,使用–with-pcre自动找到库文件。使用–with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
--with-pcre=/home/software/pcre-8.35 \ 

指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
--with-zlib=/home/software/zlib-1.2.8 \

指向openssl安装目录
--with-openssl=/home/software/openssl-1.0.1i
原文链接:https://www.f2er.com/centos/376282.html

猜你在找的CentOS相关文章