一、环境

系统:CentOS6.4x64最小化安装

IP:    192.168.3.48

二、安装基础软件

[root@lnmp-test ~]# yum install make gcc gcc-c++ openssl-devel -y

三、创建运行nginx的用户www

[root@lnmp-test ~]# groupadd www
[root@lnmp-test ~]# useradd -s /sbin/nologin -g www www

四、安装pcre

#先下载软件
[root@lnmp-test ~]# wget http://sourceforge.net/projects/pcre/files/pcre/8.30/pcre-8.30.tar.gz/download
[root@lnmp-test ~]# tar xf pcre-8.30.tar.gz
[root@lnmp-test ~]# cd pcre-8.30
[root@lnmp-test pcre-8.30]# ./configure
[root@lnmp-test pcre-8.30]# make && make install
[root@lnmp-test pcre-8.30]# ldconfig

五、安装nginx1.6.0

安装nginx

#下载nginx软件包
[root@lnmp-test ~]# wget http://mirrors.sohu.com/nginx/nginx-1.6.0.tar.gz
[root@lnmp-test ~]# tar xf nginx-1.6.0.tar.gz
[root@lnmp-test ~]# cd nginx-1.6.0
[root@lnmp-test nginx-1.6.0]# ./configure --user=www --group=www --prefix=/usr/local/nginx-1.6.0 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6
[root@lnmp-test nginx-1.6.0]# make && make install#配置软链接
[root@lnmp-test nginx-1.6.0]# ln -s /usr/local/nginx-1.6.0/ /usr/local/nginx
[root@lnmp-test nginx-1.6.0]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

修改nginx.conf文件为以下内容

user  www www;worker_processes auto;error_log  /usr/local/nginx/logs/nginx_error.log  crit;pid        /usr/local/nginx/logs/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;events{use epoll;worker_connections 51200;multi_accept on;}http{include       mime.types;default_type  application/octet-stream;server_names_hash_bucket_size 128;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 50m;sendfile on;tcp_nopush     on;keepalive_timeout 60;tcp_nodelay on;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 256k;gzip on;gzip_min_length  1k;gzip_buffers     4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types       text/plain application/x-javascript text/css application/xml;gzip_vary on;gzip_proxied        expired no-cache no-store private auth;gzip_disable        "MSIE [1-6]\.";#limit_conn_zone $binary_remote_addr zone=perip:10m;##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.server_tokens off;#log formatlog_format  access  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for';server{listen 80 default;#listen [::]:80 default ipv6only=on;server_name www.myweb.com;index index.html index.htm index.php;root  /var/www/default;#error_page   404   /404.html;location ~ [^/]\.php(/|$){# comment try_files $uri =404; to enable pathinfotry_files $uri =404;fastcgi_pass  unix:/tmp/php-cgi.sock;fastcgi_index index.php;include fastcgi.conf;#include pathinfo.conf;}location /nginx_status {stub_status on;access_log   off;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires      30d;}location ~ .*\.(js|css)?${expires      12h;}access_log  /var/www/wwwlogs/access.log  access;}
include vhost/*.conf;
}

创建nginx启动脚本

[root@lnmp-test nginx-1.6.0]# 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'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
SCRIPTNAME=/etc/init.d/$NAMEcase "$1" instart)echo -n "Starting $NAME... "if netstat -tnpl | grep -q nginx;thenecho "$NAME (pid `pidof $NAME`) already running."exit 1fi$NGINX_BIN -c $CONFIGFILEif [ "$?" != 0 ] ; thenecho " failed"exit 1elseecho " done"fi;;stop)echo -n "Stoping $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "$NAME is not running."exit 1fi$NGINX_BIN -s stopif [ "$?" != 0 ] ; thenecho " failed. Use force-quit"exit 1elseecho " done"fi;;status)if netstat -tnpl | grep -q nginx; thenPID=`pidof nginx`echo "$NAME (pid $PID) is running..."elseecho "$NAME is stopped"exit 0fi;;force-quit)echo -n "Terminating $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "$NAME is not running."exit 1fikill `pidof $NAME`if [ "$?" != 0 ] ; thenecho " failed"exit 1elseecho " done"fi;;restart)$SCRIPTNAME stopsleep 1$SCRIPTNAME start;;reload)echo -n "Reload service $NAME... "if netstat -tnpl | grep -q nginx; then$NGINX_BIN -s reloadecho " done"elseecho "$NAME is not running, can't reload."exit 1fi;;configtest)echo -n "Test $NAME configure files... "$NGINX_BIN -t;;*)echo "Usage: $SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"exit 1;;esac#添加脚本执行权限
[root@lnmp-test nginx-1.6.0]# chmod +x /etc/init.d/nginx
[root@lnmp-test nginx-1.6.0]# echo "/usr/local/lib/" >>/etc/ld.so.conf
[root@lnmp-test nginx-1.6.0]# ldconfig#添加nginx配置文件中需要的目录
[root@lnmp-test nginx-1.6.0]# mkdir -p /var/www/default
[root@lnmp-test nginx-1.6.0]# chmod +w /var/www/default
[root@lnmp-test nginx-1.6.0]# mkdir -p /var/www/wwwlogs
[root@lnmp-test nginx-1.6.0]# chmod 777 /var/www/wwwlogs
[root@lnmp-test nginx-1.6.0]# chown -R www:www /var/www/default#重新启动nginx
[root@lnmp-test nginx-1.6.0]# /etc/init.d/nginx start
Starting nginx...  done
[root@lnmp-test nginx-1.6.0]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      29754/nginx
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      22280/sshd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1318/master
tcp        0     52 192.168.3.48:22             192.168.3.2:7461            ESTABLISHED 1473/sshd
tcp        0      0 :::22                       :::*                        LISTEN      22280/sshd
tcp        0      0 ::1:25                      :::*                        LISTEN      1318/master

验证结果

#创建站点根目录文件
[root@lnmp-test nginx-1.6.0]# echo "welcome to nginx" >> /var/www/default/index.html
#编辑/etc/hosts文件,添加,并测试结果
[root@lnmp-test nginx-1.6.0]# curl www.myweb.com
welcome to nginx#添加nginx到开机自动启动
[root@lnmp-test ~]# chkconfig --add nginx
[root@lnmp-test ~]# chkconfig nginx on

下面是后来写的安装脚本

#!/bin/bashcur_dir=$(pwd)
NGINXVERSION='nginx-1.6.0'
export LANG=zh_CN.UTF-8#Source function library.
. /etc/init.d/functionscreate_nginx_conf(){
cat >>/usr/local/nginx/conf/nginx.conf<<EOF
user  www www;worker_processes auto;error_log  /usr/local/nginx/logs/nginx_error.log  crit;pid        /usr/local/nginx/logs/nginx.pid;#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;events{use epoll;worker_connections 51200;multi_accept on;}http{include       mime.types;default_type  application/octet-stream;server_names_hash_bucket_size 128;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 50m;sendfile on;tcp_nopush     on;keepalive_timeout 60;tcp_nodelay on;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 256k;gzip on;gzip_min_length  1k;gzip_buffers     4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types       text/plain application/x-javascript text/css application/xml;gzip_vary on;gzip_proxied        expired no-cache no-store private auth;gzip_disable        "MSIE [1-6]\.";#limit_conn_zone \$binary_remote_addr zone=perip:10m;##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.server_tokens off;#log formatlog_format  access  '\$remote_addr - \$remote_user [\$time_local] "\$request" ''\$status \$body_bytes_sent "\$http_referer" ''"\$http_user_agent" \$http_x_forwarded_for';server{listen 80 default;#listen [::]:80 default ipv6only=on;server_name www.myweb.com;index index.html index.htm index.php;root  /var/www/default;#error_page   404   /404.html;location ~ [^/]\.php(/|$){# comment try_files \$uri =404; to enable pathinfotry_files \$uri =404;fastcgi_pass  unix:/tmp/php-cgi.sock;fastcgi_index index.php;include fastcgi.conf;#include pathinfo.conf;}location /nginx_status {stub_status on;access_log   off;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)\${expires      30d;}location ~ .*\.(js|css)?\${expires      12h;}access_log  /var/www/wwwlogs/access.log  access;}
include vhost/*.conf;
}
EOF
}create_nginx_init(){
cat >>/etc/init.d/nginx<<EOF
#! /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'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
SCRIPTNAME=/etc/init.d/\$NAMEcase "\$1" instart)echo -n "Starting \$NAME... "if netstat -tnpl | grep -q nginx;thenecho "\$NAME (pid \`pidof \$NAME\`) already running."exit 1fi\$NGINX_BIN -c \$CONFIGFILEif [ "\$?" != 0 ] ; thenecho " failed"exit 1elseecho " done"fi;;stop)echo -n "Stoping \$NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "\$NAME is not running."exit 1fi\$NGINX_BIN -s stopif [ "\$?" != 0 ] ; thenecho " failed. Use force-quit"exit 1elseecho " done"fi;;status)if netstat -tnpl | grep -q nginx; thenPID=\`pidof nginx\`echo "\$NAME (pid \$PID) is running..."elseecho "\$NAME is stopped"exit 0fi;;force-quit)echo -n "Terminating \$NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "\$NAME is not running."exit 1fikill \`pidof \$NAME\`if [ "\$?" != 0 ] ; thenecho " failed"exit 1elseecho " done"fi;;restart)\$SCRIPTNAME stopsleep 1\$SCRIPTNAME start;;reload)echo -n "Reload service \$NAME... "if netstat -tnpl | grep -q nginx; then\$NGINX_BIN -s reloadecho " done"elseecho "\$NAME is not running, can't reload."exit 1fi;;configtest)echo -n "Test \$NAME configure files... "\$NGINX_BIN -t;;*)echo "Usage: \$SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"exit 1;;esac
EOF
}#install_nginx
install_nginx(){cd $cur_diryum install make gcc gcc-c++ openssl-devel -y#add user www for nginxid www &>/dev/nullif [ $? -ne 0 ];thengroupadd wwwuseradd -s /sbin/nologin -g www wwwfiwget http://sourceforge.net/projects/pcre/files/pcre/8.30/pcre-8.30.tar.gz/downloadif [ $? -ne 0 ];thenecho "download pcre package is fail"exit $?fitar xf  pcre-8.30.tar.gzcd pcre-8.30./configuremake && make installif [ $? -eq 0 ];thenecho "install pcre is successful!!!"elseecho "install pcre is fail!!!"exit $?fiecho "/usr/local/lib/" >>/etc/ld.so.confldconfig#download nginx packagecd $cur_dirwget http://mirrors.sohu.com/nginx/$NGINXVERSION.tar.gzif [ $? -ne 0 ];thenecho "download nginx is fail!!!"exit $?fitar xf $NGINXVERSION.tar.gzcd $NGINXVERSION./configure --user=www --group=www --prefix=/usr/local/$NGINXVERSION --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 make && make installif [ $? -ne 0 ];thenecho "install nginx fail!!!"exit $?fi #linksln -s /usr/local/$NGINXVERSION /usr/local/nginxln -s /usr/local/nginx/sbin/nginx /usr/bin/nginxmv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak#create file nginx.confcreate_nginx_conf mkdir -p /var/www/defaultchmod +w /var/www/defaultmkdir -p /var/www/wwwlogschmod 777 /var/www/wwwlogs chown -R www:www /var/www/defaultcp /usr/local/nginx/html/index.html /var/www/default/index.html #create start scripts for nginxcreate_nginx_initchmod +x /etc/init.d/nginxchkconfig --add nginxchkconfig nginx on/etc/init.d/nginx startif [ $? -eq 0 ];thenaction "start nginx" /bin/trueecho "+---------------------------------+"echo "+------nginx  install done--------+"echo "+---------------------------------+"fi
}install_nginx

转载于:https://blog.51cto.com/ly36843/1650918

编译安装nginx-1.6.0相关推荐

  1. Ubuntu 16.04源码编译安装nginx 1.10.0

    一.下载相关的依赖库 pcre 下载地址 http://120.52.73.43/jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.t ...

  2. CentOS7.0下编译安装Nginx 1.10.0

    2019独角兽企业重金招聘Python工程师标准>>> 准备工作 安装编译工具.依赖包 $ yum -y install gcc gcc-c++ autoconf automake ...

  3. Centos7 编译安装 Nginx、MariaDB、PHP

    前言 本文主要大致介绍CentOS 7下编译安装Nginx.MariaDB.PHP.面向有Linux基础且爱好钻研的朋友.技艺不精,疏漏再所难免,还望指正. 环境简介: 系统: CentOS 7,最小 ...

  4. CentOS 6下编译安装Nginx

    CentOS 6下编译安装Nginx  By:老宁 一.准备make环境  yum -y install gcc gcc-c++ automake autoconf libtool make 二.准备 ...

  5. ubuntu14.04 nginx php编译安装,Ubuntu 14.04 编译安装 Nginx

    在Ubuntu 14.04下编译安装 Nginx过程笔记. 下载源码包 nginx 地址: http://nginx.org/en/download.html 编译前先安装两个包: 直接编译安装会碰到 ...

  6. CentOS 6.5编译安装Nginx+MySQL+PHP

    一.配置防火墙,开启80端口.3306端口,关闭SELINUX [root@Zabbix ~]# vim /etc/sysconfig/iptables -A INPUT -i lo -j ACCEP ...

  7. ansible-playbook 手工编译安装nginx

    虽然nginx也可以通过yum安装,但是如何使用源码包安装并自定义开启一些nginx功能模块,并且通过ansible下发到被管理集群呢?下面给给位看官提供一个具体实例以供参考. 首先我们需要手工编译好 ...

  8. 【资料整理】编译安装nginx

    [nginx]编译安装nginx 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 ...

  9. Centos6.4 编译安装 nginx php

    一. 准备依赖库 安装make: yum -y install gcc automake autoconf libtool make 安装g++: yum install gcc gcc-c++ 二. ...

  10. CentOS 7.5 编译安装 Nginx 1.15.3

    本文主要记录如何在CentOS 7.5中编译安装Nginx官方最新的1.15.3版本.由于像Nginx.Mysql和PHP的的源码都是用C/C++写的,所以自己的CentOS 7.5服务器上必须要安装 ...

最新文章

  1. lucene.net 应用资料
  2. fibonacci climbing-stairs
  3. PHP函数——urlencode() 函数
  4. 电脑维修:电脑维修必备工具整理
  5. sharepoint配置问题解决方案
  6. Win11提示无法安装程序怎么办 Win11提示无法安装程序的解决方法
  7. django-orm框架了解
  8. Windows 动态链接库
  9. Android ADV 虚拟卡常见错误Failed to push的解决
  10. SOAP协议和HTTP协议的区别
  11. 数据库的增删改查基本操作
  12. 9月书讯(下)| 开学季,读新书
  13. 日常收支记账,使用图表查看类别收支
  14. 查错集|No.1解决Undefined symbol xxx (referred from xxx.o)问题
  15. Windows Postman中文版
  16. 基于Android的人脸识别
  17. 基于单片机GPS定位语音智能盲人拐杖设计(毕设课设)
  18. Notepad++ 7.6.4 x64安装包
  19. UDT 最新源码分析(五) -- 网络数据收发
  20. 大学物理静电场部分公式

热门文章

  1. 开课吧:Java软件开发的优点有哪些?​
  2. Web前端开发要掌握的技能有哪些?
  3. Java架构师具备的特点有哪些?
  4. 戴尔PowerEdge 4路服务器全面升级 实现企业应用与核心业务工作负载的优异性能...
  5. Linux拷贝文件夹
  6. 技术人的危机-非理性的繁荣
  7. UDT中的epoll
  8. ABAP中分页控件的定义
  9. C#通过COM组件调用IDL的pro程序
  10. 前端跨域问题及解决方案