1、检测所需扩展是否都已安装:

 1 rpm -qa | grep "pcre"
 2 rpm -qa | grep "openssl"
 3 rpm -qa | grep "wget"
 4 rpm -qa | grep "zlib"
 5
 6 # 如果缺少某一扩展 用yum安装即可
 7 yum install pcre* -y
 8 yum install openssl* -y
 9 yum install zlib -y
10 yum install zlib-devel -y

2、下载nginx安装包:

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

3、解压:

tar -zxvf nginx-1.8.0.tar.gz

4、安装:

1 cd nginx-1.8.0
2 ./configure --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --user=www --group=www --without-select_module --without-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_uwsgi_module --without-http_scgi_module --without-http_memcached_module --without-http_limit_conn_module --without-http_limit_req_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/client-body-temp --http-proxy-temp-path=/tmp/proxy-temp --http-fastcgi-temp-path=/tmp/fastcgi-temp --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --add-module=../agentzh-headers-more-nginx-module-*/

3 make && make install 

5、启动:

1 cd /usr/local/nginx/sbin
2 ./nginx
3
4 # 重新载入配置文件
5 ./nginx -s reload

6、添加到service 服务中:

1 # 首先在/usr/bin 目录下创建nginx 软连
2 cd /usr/bin
3 ln -s /usr/local/nginx/sbin/nginx nginx
4
5 # 编写nginx 启动shell 脚本
6 cd /etc/init.d
7 vim nginx
8
9 # 代码在下方

nginx 启动代码:

  1 #!/bin/bash
  2 ######################################################
  3 ## Modify by adam.li@ismole.com at 2012-07-20 13:52 ##
  4 ## Compatible with RedHat/CentOS Debian/Ubuntu SUSE ##
  5 ######################################################
  6
  7 # Support chkconfig on RedHat/CentOS
  8 # chkconfig:   2345 90 60
  9 # description: nginx
 10 # processname: nginx
 11 # config:      /usr/local/nginx/conf/nginx.conf
 12 # pidfile:     /var/run/nginx.pid
 13
 14 # Support Linux Standard Base Core Specification 3.2
 15 ### BEGIN INIT INFO
 16 # Provides:          nginx
 17 # Required-Start:    $local_fs $syslog $network
 18 # Required-Stop:
 19 # Default-Start:     2 3 4 5
 20 # Default-Stop:      0 S 1 6
 21 # Short-Description: start/stop nginx daemon
 22 # Description:       nginx is a web server, http and mail proxy server
 23 ### END INIT INFO
 24
 25 #debug
 26 #set -x
 27 #check unbound variables
 28 #set -u
 29 # Scripts PATH enviroment
 30 export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
 31 # disable core dump
 32 ulimit -c 0
 33 # return value
 34 RETVAL=0
 35 # nginx general config
 36 PROG="nginx"
 37 SYMLINK=$(readlink -f /usr/local/nginx)
 38 BASEDIR=${SYMLINK:-/usr/local/nginx}
 39 DAEMON="${BASEDIR}/sbin/nginx"
 40 CONF="${BASEDIR}/conf/nginx.conf"
 41 PIDFILE="/var/run/${PROG}.pid"
 42 LOCKFILE="/var/lock/$PROG"
 43 # nginx start timeout milliscond
 44 STARTTIME=10000
 45 # nginx stop timeout milliscond
 46 STOPTIME=10000
 47
 48 #Common Function
 49 color_msg(){
 50     local COLOR=$1
 51     local MSG=$2
 52     OFFSET="\033[60G"
 53     NORMAL="\033[0m"
 54     case $COLOR in
 55         red)
 56             COLOR="\033[1;40;31m"
 57             ;;
 58         green)
 59             COLOR="\033[1;40;32m"
 60             ;;
 61         yellow)
 62             COLOR="\033[1;40;33m"
 63             ;;
 64         *)
 65             COLOR="\033[0m"
 66             ;;
 67     esac
 68     echo -en "$OFFSET [$COLOR $MSG $NORMAL"
 69     echo     "]"
 70 }
 71
 72 configtest() {
 73     echo -n "Configtest $PROG : "
 74     $DAEMON -tq -c $CONF >/dev/null 2>&1
 75     if [ $? -eq 0 ] ;then
 76         color_msg green SUCCESS
 77     else
 78         color_msg red FAILED && exit 1
 79     fi
 80 }
 81
 82 start() {
 83     echo -n "Starting $PROG : "
 84     PROC_PID=$(pgrep -P 1 -u root ^$PROG)
 85     if [ -n "$PROC_PID" ]; then
 86         echo -n "is already running."
 87         color_msg yellow WARNING
 88     else
 89         $DAEMON -c $CONF >/dev/null 2>&1
 90         if [  $? -eq 0 ]; then
 91             color_msg green SUCCESS && touch $LOCKFILE
 92         else
 93             color_msg red FAILED && exit 1
 94         fi
 95     fi
 96 }
 97
 98 stop() {
 99     echo -n "Stopping $PROG : "
100     PROC_PID=$(pgrep -P 1 -u root ^$PROG)
101     if [ -z "$PROC_PID" ]; then
102         echo -n "is not running."
103         color_msg yellow WARNING
104     else
105         kill -TERM ${PROC_PID} >/dev/null 2>&1
106         while [ "$STOPTIME" -gt 0 ]; do
107             kill -0 ${PROC_PID} >/dev/null 2>&1 || break
108             STOPTIME=$(($STOPTIME-1))
109             echo -n "." && sleep 0.001s
110         done
111         if [ "$STOPTIME" -le 0 ]; then
112             color_msg red TIMEOUT && exit 1
113         else
114             color_msg green SUCCESS
115             rm -f $PIDFILE $LOCKFILE
116         fi
117     fi
118 }
119
120 restart() {
121         echo -n "Restart $PROG : "
122         echo
123         echo -en "\t" && stop
124         echo -en "\t" && start
125 }
126
127 reload() {
128     echo -n "Reloading $PROG : "
129     PROC_PID=$(pgrep -P 1 -u root ^$PROG)
130     if [ -n "$PROC_PID" ]; then
131         kill -HUP ${PROC_PID} >/dev/null 2>&1
132         if [  $? -eq 0 ]; then
133             color_msg green SUCCESS
134         else
135             color_msg red FAILED && exit 1
136         fi
137     else
138         echo -n "is not running."
139         color_msg yellow WARNING
140     fi
141 }
142
143 status() {
144     PROC_PID=$(pgrep -P 1 -u root ^$PROG)
145     if [ -z "$PROC_PID" ];then
146         echo "$PROG is stopped"
147         exit 3
148     else
149         echo "$PROG (pid $PROC_PID) is running..."
150         exit 0
151     fi
152 }
153
154 quit() {
155     echo -n "Quit $PROG : "
156     PROC_PID=$(pgrep -P 1 -u root ^$PROG)
157     if [ -z "$PROC_PID" ]; then
158         echo -n "is not running."
159         color_msg yellow WARNING
160     else
161         kill -QUIT ${PROC_PID} >/dev/null 2>&1
162         while [ "$STOPTIME" -gt 0 ]; do
163             kill -0 ${PROC_PID} >/dev/null 2>&1 || break
164             STOPTIME=$(($STOPTIME-1))
165             echo -n "." && sleep 0.001s
166         done
167         if [ "$STOPTIME" -le 0 ]; then
168             color_msg red TIMEOUT && exit 1
169         else
170             color_msg green SUCCESS
171             rm -f $PIDFILE $LOCKFILE
172         fi
173     fi
174 }
175
176 logrotate() {
177     echo -n "Re-opening $PROG log file : "
178     PROC_PID=$(pgrep -P 1 -u root ^$PROG)
179     if [ -z "$PROC_PID" ]; then
180         echo -n "is not running."
181         color_msg yellow WARNING
182     else
183         kill -USR1 ${PROC_PID} >/dev/null 2>&1
184         if [ $? -eq 0 ]; then
185             color_msg green SUCCESS
186         else
187             color_msg red FAILED && exit 1
188         fi
189     fi
190 }
191
192 case "$1" in
193     configtest)
194         configtest
195         ;;
196     start)
197         configtest
198         start
199         ;;
200     stop)
201         stop
202         ;;
203     restart|try-restart)
204         configtest
205         restart
206         ;;
207     reload|force-reload)
208         configtest
209         reload
210         ;;
211     status)
212         status
213         ;;
214     quit)
215         quit
216         ;;
217     logrotate)
218         logrotate
219         ;;
220     *)
221        echo $"Usage: $0 {configtest|start|stop|restart|reload|status|quit|logrotate}"
222        exit 1
223     ;;
224 esac

View Code

最后启动:

# 添加可执行权限chmod +x nginx service nginx start

转载于:https://www.cnblogs.com/gouge/p/7098850.html

Linux 安装nginx相关推荐

  1. Linux安装Nginx 作者:哇塞大嘴好帅

    Linux安装Nginx 作者:哇塞大嘴好帅 作者:哇塞大嘴好帅哇塞大嘴好帥 1.环境确保工作 如果ls等指令失效输入 export PATH=$PATH:/usr/local/sbin:/usr/l ...

  2. 服务器搭建--Linux安装nginx

    安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境. 一. gcc 安装 安装 nginx 需要 ...

  3. Linux 安装 nginx 详细教程

    文章目录 Linux 安装 nginx 详细步骤 ①安装依赖包 ②下载并解压安装包 ③安装 nginx ④启动 nginx 服务 ⑤nginx 反向代理 提示:以下是本篇文章正文内容,Linux 系列 ...

  4. linux安装nginx教程

    linux安装nginx教程 安装依赖包 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 下载安装包 # 我是装 ...

  5. Linux 安装nginx, 搭建nginx文件服务器

    在linux安装nginx web 服务器,安装后再修改配置文件,将该主机作为一个文件服务器,最终效果如下图: 安装nginx 安装依赖包 yum install -y gcc pcre-devel ...

  6. Linux安装Nginx、Redis、django

    部署Nginx 部署Redis 安装Redis redis事物 服务器管理命令 慢查询日志 主从复制 Redis-Sentinel cluser分片集群 安装python 操作redis数据 部署Dj ...

  7. linux 安装nginx php mysql 配置文件在哪_linux下 php+nginx+mysql安装配置

    我主要是用来安装php,以及nginx和php的交互. 一 安装插件 可以选择YUM安装或者源码编译安装gccgcc-c++zlib pcre pcre-devel libevent libevent ...

  8. Centos 6.5 linux 安装nginx

    2019独角兽企业重金招聘Python工程师标准>>> 本文讲述一下如何在Centos 6.5 操作系统上安装网站平台软件nginx,在很多的linux操作系统上nginx是很受欢迎 ...

  9. linux安装nginx防火墙,Centos7 防火墙关闭与nginx无法访问

    默认情况下,Centos7防火墙是打开的,如果你没有关闭他,你安装nginx后启动,是无法访问到nginx服务的. 所以需要做这件事 1.启动nginx 启动前先看它启动没有,通过linux命令查看所 ...

  10. Linux安装Nginx,附Nginx安装包

    环境:能联网的CentOS6.4 第一步: 下载安装包(用的是稳定版) 网址:http://nginx.org/en/download.html 第二步: 安装c++编译环境 切换到root用户命令行 ...

最新文章

  1. 【控制】《多无人机协同控制技术》周伟老师-第11章-多无人机协同航迹规划方法
  2. python 文本分析库_Python有趣|中文文本情感分析
  3. 400W的TVS型号大全
  4. 五十六、TodoList的三种写法,祭奠我的前端之路
  5. C语言结构体与联合体
  6. php如何定义和使用常量,如何在PHP中定义和使用常量
  7. Linux Shell编程(4)——shell特殊字符(上)
  8. 电脑软件:推荐5款实用的效率软件,每一款都爱不释手!
  9. 长能耐了?想造反了?你老婆没了.......
  10. 【电赛】一阶卡尔曼滤波器 滤波效果良好
  11. filepermission java,Java FilePermission getActions()方法与示例
  12. win10系统windows hello无法设置 windows hello设置开启教程
  13. ElasticSearch学习(二):ElasticSearch下载与运行
  14. RiPlus子主题V1.3-Unreal[幻]主题WordPress主题模板美化wp主题源码
  15. Lua二进制chunk
  16. 【latex】Latex解决表格过宽问题,自适应调整宽度;自动调整适合的表格大小
  17. Solved: ERROR: Failed building wheel for hdbscan
  18. R语言多重比较示例:Bonferroni校正法和Benjamini Hochberg法
  19. http报文格式、GET与POST的区别
  20. 时隔一年才发现嵌入式到底指的是什么

热门文章

  1. uiautomatorviewer无法启动
  2. ThinkPad开启、禁用触摸板
  3. VS2013 Git 错误 “An error was raised by libgit2. Category = 21”
  4. as it exceeds the max of 500KB._It#39;s a date的一语双关:它不仅仅表示“约会”
  5. 交换机的工作模式:IVL和SVL
  6. C++项目 GitHub Actions操作实例
  7. tar命令中参数 cvf,xvf,cvzf,zxvf的区别
  8. QM 、QA和QC的区别
  9. 最强脱单指南:如何通过区块链应用快速找到女朋友?
  10. 手机摄像头的等效焦距