首页 » Nginx » nginx 源码安装 (ubuntu)

nginx 源码安装 (ubuntu)

原文 http://blog.csdn.net/qq_30063881/article/details/79074748

2018-01-17 02:01:49阅读(371)

1. 下载nginx源文件

nginx-1.12.2.tar.gz

2. 环境准备

gcc gcc-c++ pcre prre-devel zlib zlib-devel openssl openssl-devel

3. 检查nginx安装依赖,并配置安装选项
cd /opt/nginx-1.12.2/
./configure  
 --prefix=/opt/nginx\
 --with-http_ssl_module\
 --with-http_sub_module\
 --with-http_flv_module\
 --with-http_gzip_static_module\
 --with-pcre
//缺少 pcre 安装包(笔者用的是ubuntu)
apt install libpcre3 libpcre3-dev
//缺少 openssl 安装包(笔者用的是ubuntu)
apt install openssl
apt install libssl-dev
//再次执行
./configure  
 --prefix=/opt/nginx\
 --with-http_ssl_module\
 --with-http_sub_module\
 --with-http_flv_module\
 --with-http_gzip_static_module\
 --with-pcre 
4.编译并安装
make && make install
5. 将nginx 加入系统服务
cd  /etc/init.d
touch nginx
chmod +x /etc/init.d/nginx
//nginx 脚本内容
  1 #!/bin/sh
  2 ### BEGIN INIT INFO
  3 # Provides:          nginx
  4 # Required-Start:    $all
  5 # Required-Stop:     $all
  6 # Default-Start:     2 3 4 5
  7 # Default-Stop:      0 1 6
  8 # Description:       starts and stops the nginx web server
  9 ### END INIT INFO
 10 
 11 PATH=/opt/nginx
 12 DESC="nginx daemon"
 13 NAME="nginx"
 14 
 15 DAEMON=$PATH/sbin/$NAME
 16 
 17 CONFIGFILE=$PATH/conf/$NAME.conf
 18 
 19 PIDFILE=$PATH/logs/$NAME.pid
 20 
 21 SCRIPTNAME=/etc/init.d/$NAME
 22 
 23 # Gracefully exit if the package has been removed.
 24 test -x $DAEMON || exit 0
 25 
 26 
 27 #
 28 #   Function that starts the daemon/service.
 29 #
 30 d_start() {
 31 $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
 32 }
 33 
 34 #
 35 #   Function that stops the daemon/service.
 36 #
 37 d_stop() {
 38 $DAEMON -s stop || echo -n "nginx is stop"
 39 }
//将nginx 注册为系统服务
//ubuntu
update-rc.d -f nginx defaults //注册
update-rc.d -f nginx remove //移除
//centos
chkconfig --add nginx //注册
chkconfig --del nginx //移除
6. 启动nginx
service naginx start
7. 检测
curl localhost 
//或者浏览器输入
localhost

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹