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. pycharm中安装可以贴图片的Markdown插件

    方法一:(测试成功) 先安装官方推荐的Markdown support插件,再安装Paste images into MarkDown 如果Paste images into MarkDown插件在线 ...

  2. SQL Server数据类型总结

    1.char char [(n)]存储固定长度的非Unicode字符串数据.n定义字符串长度,并且必须是1到8,000之间的值.存储大小为n个字节. 2.varchar varchar [(n | m ...

  3. 遇到问题-----cas4.2.x登录成功后报错No principal was found---cas中文乱码问题完美解决

    情况 我们之前已经完成了cas4.2.x登录使用MongoDB验证方式并且自定义了加密. 单点登录(十五)-----实战-----cas4.2.x登录mongodb验证方式实现自定义加密 但是悲剧的是 ...

  4. 【Oracle 12c】最新CUUG OCP-071考试题库(55题)

    55.(13-3) choose the best answer: Which statement is true regarding the SESSION_PRIVS dictionary vie ...

  5. Centos安装Ruby2.2.3

    升级软件包版本 (PS:我没有升级,一是太慢了,二是不知道更新完之后是否会影响其他的应用) #升级所有包,改变软件设置和系统设置,系统版本内核都升级 yum -y update #升级所有包,不改变软 ...

  6. [CSS3] 3D桃心

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. winserver2008安装tomcat+mysql+httpd+redis环境

    1. 装tomcat和jdk http://www.cnblogs.com/SHI520/p/4546849.html     2. 安装mysql5.7 https://www.jb51.net/a ...

  8. solr安装教程

    Solr Solr is the popular, blazing-fast, open source enterprise search platform built on Apache Lucen ...

  9. Kafka入门学习--基础

    Kafka是什么 Kafka是最初由Linkedin公司开发,是一个分布式.支持分区的(partition).多副本的(replica),基于zookeeper协调的分布式消息系统,它的最大的特性就可 ...

  10. npm 常用配置

    npm config list/ls 显示配置信息npm config list/ls -l 更详细npm -h 显示帮助信息,建议多查看npm -l display full usage info ...