CentOs7.3 编译安装 Nginx 1.9.9
安装
安装依赖
- $ yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
下载并解压
编译
编译时候可以指定编译参数,参考文章尾部:常用编译选项
- $ cd Nginx-1.9.9
- $ ./configure
安装
- $ make
- $ make && make install
默认安装在/usr/locale/Nginx
里面有四个目录:
常用命令
正确性检查
启动
如果不能访问,检查防火墙并关闭防火墙
centos 6.x 关闭 iptables
centos 7.x 关闭firewall
- $ ssystemctl status firewalld.service # 查看状态
- $ systemctl stop firewalld.service # 停止firewall
浏览器输入本机IP ,看到如下内容证明安装成功
停止
重启
常用编译选项
- ./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