1.下载nginx源码包

wget  http://nginx.org/download/nginx-1.11.12.tar.gz

2.解压该tar包

tar zxvf nginx-1.11.12.tar.gz

3.编译参数说明

--prefix=path   定义一个目录来保存你的nginx的提供功能的文件夹,就这好比我们安装软件的时候软件存放的目录,如果我们在编译的不指定安装位置,那么默认的位置/usr/local/nginx 目录

--sbin-path=path 设置nginx执行脚本的位置,这里如果设置在path变量里面,就可以在bash环境下,任意使用nginx命令,默认位置prefix/sbin/nginx  注意这里的prefix是在配置文件里面配置的路径

--conf-path=path 配置nginx配置文件的路径,如果不指定这个选项,那么配置文件的默认路径就会是 prefix/conf/nginx.conf

--pid-path =path 配置nginx.pid file的路径,一般来说,进程在运行的时候的时候有一个进程id,这个id会保存在pid file里面,默认的pid file的放置位置是prefix/logs/nginx.pid

--error-log-path=path 设置错误日志的存放路径,如果不指定,就默认 prefix/logs/error.log

--http-log-path= path 设置http访问日志的路径,如果不指定,就默认 prefix/logs/access.log

--user=name  设置默认启动进程的用户,如果不指定,就默认 nobody

--group=name 设置这个用户所在的用户组,如果不指定,依然是nobody

这些是我们常用的编译选项,其他的可以均保持默认,如需特殊指定,可上nginx官网查阅 http://nginx.org/en/docs/configure.html

下面是一些不常用的选项

--with-http_ssl_module -开启HTTP SSL模块,使NGINX可以支持HTTPS请求。需要安装了OPENSSL

--with-http_flv_module

--with-http_stub_status_module - 启用 "server status" 页(可有可无)

--without-http_gzip_module - 禁用 ngx_http_gzip_module. 如果启用,需要 zlib 。

--without-http_ssi_module - 禁用 ngx_http_ssi_module

--without-http_referer_module - 禁用 ngx_http_referer_module

--without-http_rewrite_module - 禁用 ngx_http_rewrite_module. 如果启用需要 PCRE 。

--without-http_proxy_module - 禁用 ngx_http_proxy_module

--without-http_fastcgi_module - 禁用 ngx_http_fastcgi_module

--without-http_memcached_module - 禁用 ngx_http_memcached_module

--without-http_browser_module - 禁用 ngx_http_browser_module

--http-proxy-temp-path=PATH - Set path to the http proxy temporary files

--http-fastcgi-temp-path=PATH - Set path to the http fastcgi temporary files

--without-http - 禁用 HTTP server(用作代理或反向代理)

--with-mail - 启用 IMAP4/POP3/SMTP 代理模块

--with-mail_ssl_module - 启用 ngx_mail_ssl_module

--with-openssl=DIR - Set path to OpenSSL library sources

4.源码编译步骤

a.切换到解压目录

cd nginx-1.11.12

b.执行configure命令

sudo ./configure

c.执行make命令

sudo make

d.执行安装命令

sudo make install

注意:

如果编译过程出现the HTTP rewrite module requires the PCRE library.的错误

需要安装以下插件

安装pcre

sudo apt install   libpcre3 libpcre3-dev

安装 openssl

sudo apt-get intall openssl libssl-dev

5.使用sysv-rc-conf(chkconfig)的方式管理nginx服务

安装sysv-rc-conf:sudo apt-get install sysv-rc-conf

a.首先添加nginx服务管理的脚本

sudo vim  /etc/init.d/nginx

#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx' ### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO # Author: licess
# website: http://lnmp.org PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid case "$1" in
start)
echo -n "Starting $NAME... " if netstat -tnpl | grep -q nginx;then
echo "$NAME (pid `pidof $NAME`) already running."
exit 1
fi $NGINX_BIN -c $CONFIGFILE if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;; stop)
echo -n "Stoping $NAME... " if ! netstat -tnpl | grep -q nginx; then
echo "$NAME is not running."
exit 1
fi $NGINX_BIN -s stop if [ "$?" != 0 ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;; status)
if netstat -tnpl | grep -q nginx; then
PID=`pidof nginx`
echo "$NAME (pid $PID) is running..."
else
echo "$NAME is stopped"
exit 0
fi
;; force-quit)
echo -n "Terminating $NAME... " if ! netstat -tnpl | grep -q nginx; then
echo "$NAME is not running."
exit 1
fi kill `pidof $NAME` if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;; restart)
$0 stop
sleep 1
$0 start
;; reload)
echo -n "Reload service $NAME... " if netstat -tnpl | grep -q nginx; then
$NGINX_BIN -s reload
echo " done"
else
echo "$NAME is not running, can't reload."
exit 1
fi
;; configtest)
echo -n "Test $NAME configure files... " $NGINX_BIN -t
;; *)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
exit 1
;; esac

b.给脚本添加执行权限

sudo chmod +x /etc/init.d/nginx

sudo  sysv-rc-conf --list #查看一下list中有没有刚刚加进去的这个nginx管理脚本

c.添加到开机自启动

sudo sysv-rc-conf nginx on(这一步实际上就是实现了一个链接)

d.加载安装服务

sudo systemctl enable nginx(如果不愿意重启的话)

e.启动nginx服务

sudo service nginx start

f.测试nginx

curl localhost

ubuntu 16.04通过源码方式安装nginx的更多相关文章

  1. Ubuntu 16.04通过源码安装QUEM虚拟机

    下载编译安装: wget http://download.qemu-project.org/qemu-2.9.0.tar.xz tar xvJf qemu-2.9.0.tar.xz cd qemu-2 ...

  2. 通过源码编译安装VIM

    开发中使用的是Ubuntu 12.04 LTS,通过sudo apt-get install vim安装的版本较低,不支持YCM,所以,用源码编译并安装最新的Vim. 卸载旧版本的Vim: sudo ...

  3. Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用【转】

    本文转载自:http://www.linuxdiyf.com/linux/24086.html Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用 发布时间:2016-09 ...

  4. ubuntu 16.04 anaconda 4.2.0 安装tensorflow 报错

    ubuntu 16.04 anaconda 4.2.0 安装tensorflow 报错. 安装pyenv后,在pyenv环境内安装 anaconda,然后再安装tensorflow不再报错,比较奇怪, ...

  5. ubuntu 16.04上源码编译和安装cgal并编写CMakeLists.txt | compile and install cgal on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/39ab7ed9/,欢迎阅读最新内容! compile and install cgal on ubuntu 16.04 Guide ...

  6. Ubuntu 16.04上源码编译和安装pytorch教程,并编写C++ Demo CMakeLists.txt | tutorial to compile and use pytorch on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/54e7a3d8/,欢迎阅读最新内容! tutorial to compile and use pytorch on ubuntu ...

  7. ubuntu 16.04上 mysql 5.7 安装笔记

    一 安装 ubuntu 采用APT安装方式,可参考: Ubuntu 安装mysql和简单操作 Ubuntu 16.04安装MySQL(5.7.18) A Quick Guide to Using th ...

  8. Windows 10+Ubuntu 16.04在MBR分区上安装双系统(转)

    以下内容转自这篇博客: http://www.cnblogs.com/Duane/p/5424218.html http://www.cnblogs.com/Duane/p/6776302.html( ...

  9. Linux下通过源码编译安装程序

    本文简单的记录了下,在linux下如何通过源码安装程序,以及相关的知识.(大神勿喷^_^) 一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 库文件: ...

随机推荐

  1. Log4Net配置使用简记

    1,引用Log4Net.dll .当前为2.0.8.0版,可添加Nuget包.我的办法是从下载的包中直接引用相应.net版本的dll以减小项目体积 2,在App.config中增加<sectio ...

  2. iOS9 视频播放

       self.videoFileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:///%@", self ...

  3. Web 应用简单测试方案

    测试:一定要分阶段测试,先确定入队列成功,再测试队列的执行是否成功. 功能点: 1. 翻页2. 加精3. 置顶4. 帖子浏览量(PV)5. 发帖6. 回复7. 评论 8. crontab 脚本 @20 ...

  4. C#基础入门 六

    C#基础入门 六 静态类进阶 静态构造方法 用于初始化任何静态数据,或用于执行仅需执行一次的特定操作,在创建第一个实例或引用任何静态成员之前,将自动调用静态构造函数,静态构造方法是无参数的. publ ...

  5. Linux(一) - Unix&Linux 历史

    Unix Unix 的诞生 Unix的历史可以追溯到20世纪60年代中期,当时麻省理工学院,AT&T,贝尔实验室和通用电气公司联合开发了一种名为Multics的操作系统,Multics 中存在 ...

  6. HTML5和App之争论

    2013了,移动互联网火了几年,我们也看清了原生App的真面目,App很多很好,但是盈利很难,这时我们不得不把目光重新转向HTML5. 简单地说,HTML5是一个新技术,可以让开发者基于Web开发的A ...

  7. 如何关闭SQL进程

    --通过下面的查询得到trace ID select * from sys.traces --修改下面的@traceid参数,关闭,删除对应的trace exec sp_trace_setstatus ...

  8. 数据库访问接口(ODBC、OLE DB、ADO)

    最近在学C#的数据库编程,对于数据库接口技术这块的知识一直比较模糊,网上查了不少资料,看了几天还是朦朦胧胧的,只能做些笔记再研究了. 我们都知道,“数据库”是指一组相关信息的集合,最早的计算机应用之一 ...

  9. Help Jimmy(动态规划)

    点击打开链接 Help Jimmy Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12168   Accepted: 402 ...

  10. [CSS3] :nth-child的用法

    :nth-child(2)选取第几个标签,“2可以是你想要的数字” .demo01 li:nth-child(2){background:#090} :nth-child(n+4)选取大于等于4标签, ...