RHEL7下的Nginx的配置安装

一、    安装前的准备

1.      建立RHELyum存储库

#vim /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/rhel/7/$basearch/

gpgcheck=0

enabled=1

 

2.      编译安装配置参数

--help#打印这个信息
  --prefix=PATH#设置安装路径
  --sbin-path=PATH#设置binary 路径
  --conf-path=PATH#设置nginx 配置文件路径
  --error-log-path=PATH#设置错误日志路径
  --pid-path=PATH#设置nginx.pid 路径
  --lock-path=PATH#设置nginx.lock路径
  --user=USER#设置没有特殊权限的用户执行
  --group=GROUP#设置没有特殊权限的用户执行
  --builddir=DIR #设置编译目录
  --with-rtsig_module #开启rtsig 模块
  --with-select_module #开启select 模块
  --without-select_module #关闭 select 模块
  --with-poll_module #启用 poll 模块
  --without-poll_module #关闭poll 模块
  --with-file-aio #开启file AIO支持
  --with-ipv6 #开启IPv6 支持
  --with-http_ssl_module #开启ssl 模块
  --with-http_spdy_module #开启spdy模块
  --with-http_realip_module #开启 realip 模块
  --with-http_addition_module #开启 addition 模块
  --with-http_xslt_module #开启 xslt模块
  --with-http_p_w_picpath_filter_module #开启 p_w_picpath_filter模块
  --with-http_geoip_module #开启geoip模块
  --with-http_sub_module #开启 sub模块
  --with-http_dav_module #开启dav 模块
  --with-http_flv_module #开启 flv模块
  --with-http_mp4_module #开启 mp4模块
  --with-http_gunzip_module #开启gunzip模块
  --with-http_gzip_static_module #开启 gzip_static模块
  --with-http_auth_request_module #开启 auth_request(身份验证请求)模块
  --with-http_random_index_module #开启random_index(随机指数)模块
  --with-http_secure_link_module #开启 secure_link(安全链接)模块
  --with-http_degradation_module #开启degradation 模块
  --with-http_stub_status_module #开启 stub_status 模块
  --without-http_charset_module #关闭 charset(字符集) 模块
  --without-http_gzip_module #关闭 gzip模块
  --without-http_ssi_module #关闭 ssi 模块
  --without-http_userid_module #关闭 userid模块
  --without-http_access_module #关闭 access模块
  --without-http_auth_basic_module #关闭 auth_basic (基本身份认证)模块
  --without-http_autoindex_module #关闭 autoindex(自动变址)模块
  --without-http_geo_module #关闭 geo模块
  --without-http_map_module #关闭 map 模块
  --without-http_split_clients_module #关闭 split_clients (划分客户端)模块
  --without-http_referer_module #关闭 referer (推荐人)模块
  --without-http_rewrite_module #关闭 rewrite (重写)模块
  --without-http_proxy_module #关闭 proxy (代理)模块
  --without-http_fastcgi_module #关闭 fastcgi模块
  --without-http_uwsgi_module #关闭 uwsgi 模块
  --without-http_scgi_module #关闭 scgi 模块
  --without-http_memcached_module #关闭 memcached 模块
  --without-http_limit_conn_module #关闭 limit_conn 模块
  --without-http_limit_req_module #关闭 limit_req模块
  --without-http_empty_gif_module #关闭 empty_gif 模块
  --without-http_browser_module #关闭 browser 模块
  --without-http_upstream_ip_hash_module#关闭 ip_hash模块
  --without-http_upstream_least_conn_module#关闭 least_conn 模块
  --without-http_upstream_keepalive_module#关闭 keepalive 模块
  --with-http_perl_module#开启perl 模块
  --with-perl_modules_path=PATH#设置perl模块路径
  --with-perl=PATH#设置perl 命令路径
  --http-log-path=PATH#设置访问日志 路径
  --http-client-body-temp-path=PATH#设置存储路径 http客户端请求主体临时文件
  --http-proxy-temp-path=PATH#设置存储路径 http代理临时文件
  --http-fastcgi-temp-path=PATH#设置 fastcgi临时文件存储路径
  --http-uwsgi-temp-path=PATH#设置 uwsgi 临时文件存储路径
  --http-scgi-temp-path=PATH#设置 scgi 临时文件存储路径
  --without-http#关闭 http server
  --without-http-cache#关闭 http cache
  --with-mail#开启 POP3/IMAP4/SMTP 协议模块
  --with-mail_ssl_module#开启 nginx mail ssl 模块
  --without-mail_pop3_module#关闭 mail pop3模块
  --without-mail_imap_module#关闭 mail imap 模块
  --without-mail_smtp_module#关闭 mail smtp 模块
  --with-google_perftools_module#开启 nginx google_perftools (谷歌性能工具)模块
  --with-cpp_test_module#开启 cpp_test 模块
  --add-module=PATH#开启external(外部)模块
  --with-cc=PATH#设置C 编译器 路径
  --with-cpp=PATH#设置 C预编译器 路径
  --with-cc-opt=OPTIONS#设置额外的C编译器选项
  --with-ld-opt=OPTIONS#设置额外的链接器选项
  --with-cpu-opt=CPU#建立指定的CPU  有效值:
  --without-pcre#关闭 PCRE 库 使用
  --with-pcre#强制使用指定的PCRE 库
  --with-pcre=DIR#指定 pcre 使用路径
  --with-pcre-opt=OPTIONS#为PCRE设置额外的构建选项
  --with-pcre-jit#构建PCRE JIT编译的支持
  --with-md5=DIR#设置路径md5库资源
  --with-md5-opt=OPTIONS#为md5设置额外的构建选项
  --with-md5-asm#使用md5汇编源
  --with-sha1=DIR#设置 sha1 库的路径
  --with-sha1-opt=OPTIONS#为sha1设置额外的构建选项
  --with-sha1-asm#使用sha1汇编源
   --with-zlib=DIR#指定 zlib 库的路径
  --with-zlib-opt=OPTIONS#为zlib 设置额外的构建选项
  --with-zlib-asm=CPU#使用 zlib汇编优化的来源
  --with-libatomic#强制 使用libatomic
  --with-libatomic=DIR#设置 libatomic 路径
  --with-openssl=DIR#设置 openssl 库的路径
  --with-openssl-opt=OPTIONS#为 openssl 设置额外的构建选项
  --with-debug#开启debug 日志
 

二、    Yum源安装方法

1.      安装nginx

[root@wjb10000 ~]# yum -y install nginx

1.       

2.      启动服务

[root@wjb10000 ~]# systemctl start nginx.service

3.      查看是否启动成功

[root@wjb10000 ~]# systemctl status nginx

clip_p_w_picpath002

或者浏览器输入服务器ip地址:

clip_p_w_picpath004

三、    源码编译安装

1.      平台编译环境使用如下指令

1.1    安装make

[root@master ~]#yum -y install gcc automake autoconf libtool make

1.2    安装g++:

[root@master ~]#yum -y install gcc gcc-c++  

 


2         下载nginx

[root@master ~]# wget http://nginx.org/download/nginx-1.10.0.tar.gz

3         创建nginx用户

[root@master ~]# useradd nginx -s /sbin/nologin

4         解压软件

[root@master ~]# tar xf nginx-1.10.0.tar.gz

5         进入目录

[root@master ~]# cd nginx-1.10.0

6         编译程序

[root@master nginx-1.10.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.10.0/ --with-http_stub_status_module --with-http_ssl_module

7         安装所需要的依赖包方法

7.1    源码安装PCRE

[root@master /]# cd /usr/local/src/

[root@master src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.21.tar.gz [root@master src]# tar -zxvf pcre2-10.21.tar.gz

[root@master src]# cd pcre2-10.21/

[root@master pcre2-10.21]# ./configure

[root@master pcre2-10.21]# make && make install

或者yum安装

[root@master /]#yum install pcre pcre-devel –y

7.2    源码安装zlib

[root@master /]# cd /usr/local/src/

[root@master src]# wget http://zlib.net/zlib-1.2.8.tar.gz

[root@master src]# tar -zxvf zlib-1.2.8.tar.gz

[root@master src]# cd zlib-1.2.8

[root@master zlib-1.2.8]# ./configure

[root@master zlib-1.2.8]# make && make install

7.3    源码安装ssl

[root@master /]# cd /usr/local/src/

[root@master ~]# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

[root@master ~]# tar -zxvf openssl-1.0.1c.tar.gz

或者yum安装

[root@master ~]#yum install openssl openssl-devel -y

7.4    重新编译成功

[root@master nginx-1.10.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.10.0/ --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre2-10.21 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1c

clip_p_w_picpath006

7.5    安装软件

[root@master nginx-1.10.0]# make && make install

7.6    创建链接

[root@wjb10000 /]# ln -s /application/nginx-1.10.0/ /application/nginx

7.7    启动服务

[root@wjb10000 /]# /application/nginx/sbin/nginx

7.8    查看服务

[root@wjb10000 /]# lsof -i :80

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

nginx   24186  root    6u  IPv4  83053      0t0  TCP *:http (LISTEN)

nginx   24187 nginx    6u  IPv4  83053      0t0  TCP *:http (LISTEN)

[root@wjb10000 /]# netstat -lnt | grep 80

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN

7.9    网页测试

clip_p_w_picpath008