通过yum安装
安装yum源
# Centos6 yum源
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# Centos7 yum源
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
如果其他版本的官方源修改url即可,复制nginx的yum源安装包地址,替换上面命令的URL地址即可安装,如图
手动配置yum源
vim /etc/yum.repos.d/nginx.repo
# 写入以下内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
编译安装
安装所包
# Centos
# 安装编译工具gcc
yum groupinstall "Development Tools"
yum groupinstall "开发工具" # 若为中文
yum install pcre pcre-devel
# 要Perl兼容的正则表达式(PCRE)库来编译Nginx。 Nginx的Rewrite和HTTP核心模块使用PCRE作为其正则表达式的语法,
# 需要两个包pcre和pcre-devel,第一个包提供了编译版本的库,而第二个包提供了开发头文件和源文件来编译项目。
yum install zlib zlib-devel
# zlib库为开发人员提供了压缩算法。在Nginx的各个模块中使用的gzip压缩功能需要zlib库。
yum install openssl openssl-devel
# Nginx使用OpenSSL库来提供ssl连接。因此,我们需要安装openssl库及其开发包。
# ubuntu所需包一样,包名有所区别
apt-get install build-essentials zlib1g zlib1g-dev openssl openssl-dev
nginx软件包官方下载
# 最好去官方下载最新版本,知道你们懒。。。
wget http://nginx.org/download/nginx-1.12.1.tar.gz
解压编译安装
tar -zxf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure
make && make install
编译参数说明
--prefix #nginx安装目录,默认在/usr/local/nginx
--pid-path #pid问件位置,默认在logs目录
--lock-path #lock问件位置,默认在logs目录
--with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。
--with-http_dav_module #开启WebDAV扩展动作模块,可为文件和目录指定权限
--with-http_flv_module #支持对FLV文件的拖动播放
--with-http_realip_module #支持显示真实来源IP地址
--with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩
--with-http_stub_status_module #取得一些nginx的运行状态
--with-mail #允许POP3/IMAP4/SMTP代理模块
--with-mail_ssl_module #允许POP3/IMAP/SMTP可以使用SSL/TLS
--with-pcre=../pcre-8.11 #注意是未安装的pcre路径
--with-zlib=../zlib-1.2.5 #注意是未安装的zlib路径
--with-debug #允许调试日志
--http-client-body-temp-path #客户端请求临时文件路径
--http-proxy-temp-path #设置http proxy临时文件路径
--http-fastcgi-temp-path #设置http fastcgi临时文件路径
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径
--http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径
附录
默认安装选项
–without-http_charset_module
–without-http_gzip_module
–without-http_ssi_module
–without-http_userid_module
–without-http_access_module
–without-http_access_module
–without-http_autoindex_module
–without-http_geo_module
–without-http_map_module
–without-http_referer_module
–without-http_rewrite_module
–without-http_proxy_module
–without-http_fastcgi_module
–without-http_uwsgi_module
–without-http_scgi_module
–without-http_memcached_module
–without-http_limit_conn_module
–without-http_limit_req_module
–without-http_empty_gif_module
–without-http_browser_module
–without-http_upstream_ip_hash_module
–without-http_upstream_least_conn_module
–without-http_split_clients_module
默认禁用选项
–with-http_ssl_module
–with-http_realip_module
–with-http_addition_module
–with-http_xslt_module
–with-http_image_filter_module
–with-http_geoip_module
–with-http_sub_module
–with-http_dav_module
–with-http_flv_module
–with-http_mp4_module
–with-http_gzip_static_module
–with-http_random_index_module
–with-http_secure_link_module
–with-http_stub_status_module
–with-google_perftools_module
–with-http_degradation_module
–with-http_perl_module
–with-http_spdy_module
–with-http_gunzip_module
–with-http_auth_request_module