nginx编译安装

简介:

Nginx编译安装

Linux系统下Nginx的源码编译安装模块依赖性,需要依赖下面3个安装包(下面的演示版本不是最新版本,你也可以下载最新的版本,只要把版本号修改一下即可):

一般yum安装以下几个插件:

1
yum -y install pcre-devel zlib-devel openssl openssl-devel

但这里我们选择编译安装:

1:ssl 功能需要 openssl 库 ( 下载:http://www.openssl.org/source) 

1
wget http://www.openssl.org/source/openssl-fips-1.0.2l.tar.gz

2:gzip 模块需要 zlib 库 ( 下载:http://www.zlib.net/)

1
wget http://zlib.net/zlib-1.2.11.tar.gz

3:rewrite 模块需要 pcre 库 ( 下载:http://www.pcre.org/ )

1
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz


############## 一、安装OpenSSL ######################

下载地址 https://www.openssl.org/source/

1
2
3
4
5
wget https: //www .openssl.org /source/openssl-1 .0.2l. tar .gz
tar  zxvf openssl-1.0.2l. tar .gz
cd  openssl-1.0.2l/
. /config  --prefix= /usr/  --openssldir= /usr/  shared;
  make  &&  sudo  make  install


################ 二、安装PCRE ########################
下载地址 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

1
2
3
4
wget  ftp : //ftp .csx.cam.ac.uk /pub/software/programming/pcre/pcre-8 .41. tar .gz
tar  zxvfpcre-8.41. tar .gz
. /configure  --prefix= /opt/pcre-8 .41 ;
  make  &&  sudo  make  install


################ 三、安装ZLIB ########################

1
2
3
4
5
tar  -zxvf zlib-1.2.11. tar .gz
cd  zlib-1.2.11
. /configure
make
make  install


################ 三、安装Nginx ########################

下载Nginx源码包(stable version)

1
wget http://nginx.org/download/nginx-1.12.2.tar.gz

创建用户与组:

1
2
groupadd nginx
useradd -s /sbin/nologin -g nginx -M nginx

解压

1
2
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2/

配置编译环境(--with-pcre、--with-openssl的路径是源码路径,pcre、openssl的安装路径在/opt,但这里只需要源码路径)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
. /configure  \
--prefix= /opt/nginx  \
--user=nginx \
--group=nginx \
--error-log-path= /opt/nginx/logs/nginx/error .log \
--http-log-path= /opt/nginx/logs/nginx/access .log \
--pid-path= /opt/nginx/run/nginx/nginx .pid \
--lock-path= /opt/nginx/var/lock/nginx .lock \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre=.. /pcre-8 .41 \
--with-http_realip_module \(更方便的获取真实客户端IP,可以使用nginx http_realip_module模块解决)
--with-openssl ( #编译路径指定--with-openssl=/opt/openssl-1.0.21)


#以上编译安装nginx后,--http-client-body-temp-path、--http-proxy-temp-path、--http-fastcgi-temp-path、--http-uwsgi-temp-path、--http-scgi-temp-path默认的路径就在/usr/local/nginx下,分别是client_body_temp、proxy_temp、fastcgi_temp、scgi_temp、uwsgi_temp


1
2
make  &&  make  install
添加一个nginx主程序的符号链接 ln  -s  /web/nginx/sbin/nginx  /usr/local/sbin/


配置参数描述:

--with-xxx    代表默认没有打开的功能
--without-xxx 代表默认打开的功能

--prefix=path 代表安装路径
--sbin-path=path  sbin路径
--conf-path  配置文件
--pid-path 代表进程号保存文件
--error-log-path错误日志
--lock-path  锁文件
--user   ps看到的启动进程用户
--group ps看到的启动进程用户所在组
--with-http_ssl_module
--with-http_flv_module


将nginx加入service来管理启动与停止:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
vi  /etc/init .d /nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# 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: /opt/nginx/conf/nginx.conf
nginxd= /opt/nginx/sbin/nginx
nginx_config= /opt/nginx/conf/nginx .conf
nginx_pid= /opt/nginx/run/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  /opt/nginx/run/nginx/nginx .pid  #这里也要注意修改你的nginx的pid路径
}
# reload nginx service functions.
reload() {
  echo  -n $ "Reloading $prog: "
  killproc $nginxd -HUP
  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


1
2
3
4
5
chmod  +x  /etc/init .d /nginx
chkconfig --add nginx
chkconfig nginx on
chkconfig --list nginx
nginx           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭





      本文转自ling118 51CTO博客,原文链接:http://blog.51cto.com/meiling/1978442,如需转载请自行联系原作者





相关文章
|
10天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
14 0
|
1月前
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
72 6
|
2月前
|
负载均衡 Ubuntu 应用服务中间件
|
3月前
|
Unix 应用服务中间件 Linux
1-Nginx介绍及安装(源码安装)
1-Nginx介绍及安装(源码安装)
44 4
|
2月前
|
缓存 负载均衡 应用服务中间件
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
68 1
如何在 CentOS 7 上为 NGINX 安装开源 HTTP 加速器:Varnish
|
1天前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
5 1
|
23天前
|
网络协议 应用服务中间件 网络安全
linxu安装nginx
linxu安装nginx
51 0
|
30天前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
193 0
|
1月前
|
负载均衡 应用服务中间件 nginx
|
1月前
|
应用服务中间件 nginx Windows
windows下快速安装nginx 并配置开机自启动
windows下快速安装nginx 并配置开机自启动
windows下快速安装nginx 并配置开机自启动