1:安装必要的库

Bash
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

2:创建Nginx用户和组

Bash
groupadd www
#创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g www -M www

3:下载并解压Nginx

Bash
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -xzvf nginx-1.12.0
cd nginx-1.12.0

4:配置并编译安装

Bash
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
make && make install

参数说明:

nginx大部分常用模块,编译时./configure --help以--without开头的都默认安装。

--prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx

--conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf

--user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。--group=name类似

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

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

--with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装

--with-http_stub_status_module : 用来监控 Nginx 的当前状态

--with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址

--add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)

5:配置Nginx命令和服务并开机启动

Bash
vim /etc/init.d/nginx

复制一下代码到上面的文件

Bash
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/nginx.pid RETVAL=0
prog="nginx" # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions.
start() { if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL } # Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
} # reload nginx service functions.
reload() { echo -n $"Reloading $prog: "
$nginxd -s reload
#if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"
RETVAL=$?
echo } # See how we were called.
case "$1" in
start)
start
;; stop)
stop
;; reload)
reload
;; restart)
stop
start
;; status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac exit $RETVAL
Bash
cd /etc/rc.d/init.d
#附加执行权限
chmod 755 /etc/init.d/nginx
#开机自启
chkconfig --level 345 nginx on
service nginx start #可选 start | stop | restart | reload | status | help

6.查看系统IP地址,打开nginx的本地网页

[root@bogon ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:9C:2B:A5
inet addr:192.168.16.87 Bcast:192.168.16.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9c:2ba5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1648500 errors:0 dropped:0 overruns:0 frame:0
TX packets:2193 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1606718906 (1.4 GiB) TX bytes:176876 (172.7 KiB)

CentOS6.9编译安装Nginx1.12的更多相关文章

  1. CentOS-7.3.1611编译安装 Nginx-1.12.1+mysql-5.7.19+PHP-7.1.8+zabbix-3.4.1

    CentOS-7.3.1611编译安装 Nginx-1.12.1+mysql-5.7.19+PHP-7.1.8+zabbix-3.4.1 下载软件 1.下载nginx http://nginx.org ...

  2. CentOS6.3编译安装Nginx1.4.7 + MySQL5.5.25a + PHP5.3.28

    [准备工作] #在编译安装lnmp之前,首先先卸载已存在的rpm包. rpm -e httpd rpm -e mysql rpm -e php yum -y remove httpd yum -y r ...

  3. centos 6.9 编译安装 Nginx1.12.1

    centos 6.9 使用yum 安装 Nginx1.12.1 Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由伊戈 ...

  4. 编译安装 Nginx1.12.1

    本文描述Nginx 的源码编译安装过程 ############## 一.安装OpenSSL ###################### 下载地址 https://www.openssl.org/s ...

  5. CentOS6.4下安装Nginx1.12.2

    1.安装GCC安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装 yum install gcc-c++ 2.安装PCRE-devel PCR ...

  6. Linux下编译安装Nginx1.12

    [准备工作] 所有操作需要在root用户下 本机测试案例系统信息:centos7.3 安装路径:/usr/local/nginx [安装Nginx] 先安装如下依赖包 $ yum install gc ...

  7. CentOS6.5编译安装Nginx1.8.1+MySQL5.5.48+PHP5.2.17+xcache3.2+ZendOptimizer-3.3.9

    一.安装Nginx: 1.解决依赖关系 编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries& ...

  8. CentOS6.9编译安装nginx1.4.7

    1.系统安装开发包组和zlib-devel,关闭iptables [root@bogon ~]# yum groupinstall -y "Development Tools" [ ...

  9. 【PHP升级】CentOS6.3编译安装 PHP5.4.38

    先前安装的PHP5.3.28(参考:CentOS6.3编译安装Nginx1.4.7 + MySQL5.5.25a + PHP5.3.28),现在准备升级PHP到5.4.38,有如下几个地方需要重新编译 ...

随机推荐

  1. Redis密码设置与访问限制(网络安全)

    现在用redis缓存热数据越来越常见了,甚至一些配置,开关等等的东西也写到redis里.原因就是redis简单高效.redis里的数据也越来越重要了,例如一些业务的中间数据会暂时存放在redis里,所 ...

  2. cocos2dx - tmx地图分层移动处理

    接上一节内容:cocos2dx - 节点管理 瓦片地图(Tiled Map) 在cocos2dx文档中有简单的介绍及使用.详情可以看:http://www.cocos2d-x.org/docs/man ...

  3. 张高兴的 Windows 10 IoT 开发笔记:HC-SR04 超声波测距模块

    HC-SR04 采用 IO 触发测距.下面介绍一下其在 Windows 10 IoT Core 环境下的用法. 项目运行在 Raspberry Pi 2/3 上,使用 C# 进行编码. 1. 准备 H ...

  4. WPF popup置顶

    在程序写一个popup发现他会在置顶,在网上找了两大神代码http://www.cnblogs.com/Leaco/p/3164394.html http://blog.csdn.net/baijin ...

  5. 分享一个.NET加密工具NetEncryptor v2.1.6(破解版)

    在国外论坛闲逛,无意间看到一个.NET 加密工具.看了官网的介绍,感觉挺有意思,于是下载下来研(破)究(解)了一番. 官网地址:http://www.infralution.com/products/ ...

  6. parameterType 和 resultType

    parameterType #{} 和 ${} 1.#{}实现的是向prepareStatement中的预处理语句中设置参数值,sql语句中#{}表示一个占位符即?. 2.使用占位符#{}可以有效防止 ...

  7. 视频加载logo 2

    推荐这个网站 http://www.flaticon.com/ http://www.flaticon.com/search?word=spinner  旋转图标 http://www.flatico ...

  8. [Scikit-learn] 4.4 Dimensionality reduction - PCA

    2.5. Decomposing signals in components (matrix factorization problems) 2.5.1. Principal component an ...

  9. Problem Q

    Problem Description A factory produces products packed in square packets of the same height h and of ...

  10. Life is a Line

    Life is a Line Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tot ...