Linux编译安装Nginx

作者: 徐笔笔 | 来源:发表于2016-08-09 22:30 被阅读282次


Nginx

一.部署:

1.部署环境:

CentOS6.3

2.编译前准备:

安装编译工具:yum -y install gcc gcc-c++ automake autoconf libtool make

3.下载源码包:

cd

mkdir src

cd src

wget [ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.22.tar.gz](ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/)

wget [http://zlib.net/zlib-1.2.8.tar.gz](http://zlib.net/zlib-1.2.8.tar.gz)

wget [https://www.openssl.org/source/openssl-1.0.1g.tar.gz](https://www.openssl.org/source/openssl-1.0.1g.tar.gz)

wget [http://nginx.org/download/nginx-1.10.1.tar.gz](http://nginx.org/download/nginx-1.10.1.tar.gz)

tar -zxvf nginx-1.10.1.tar.gz

tar -zxvf pcre2-10.22.tar.gz

tar -zxvf zlib-1.2.8.tar.gz

tar -zxvf openssl-1.0.1t.tar.gz

4.编译安装:

# install pcre

cd pcre2-8.22/

./configure

make&&make install

# install zlib

cd ..

cd zlib-1.2.8/

./configure

make&&make install

# install openssl

cd ..

cd openssl-1.0.1t/

./configure

make&&make install

# install nginx

cd ..

cd nginx-1.10.1/

./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/root/src/pcre2-10.22/ --with-zlib=/root/src/zlib-1.2.8/ --with-openssl=/root/src/openssl-1.0.1t/

make&&make install

#Start Nginx

/usr/local/nginx/nginx

五.Nginx启动脚本:

#/bin/bash

# Author:lwen

# Descript: The shell is to manage the nginx

# chkconfig: 2345 33 34

# description: The Nginx HTTP Server

binpath=/usr/local/nginx/nginx;

pidpath=/usr/local/nginx/nginx.pid

if [ -f ${pidpath} ]; then

pid=`cat $pidpath`

fi

start(){

if [ -f ${pidpath} ]; then

echo "The Nginx is already running !"

else

echo "Starting Nginx ..."

$binpath

fi

}

stop(){

if [ -f ${pidpath} ]; then

echo "Stopping Nginx ..."

$binpath -s stop

else

echo "The Nginx haven't run !"

fi

}

reload() {

$binpath -s reload

}

status() {

if [ -f ${pidpath} ]; then

echo "The Nginx(pid: ${pid} ) is running..."

else

echo "The Nginx is stop!"

fi

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

reload)

reload

;;

status)

status

;;

*)

echo "The Usage: /etc/init.d/nginx (start|stop|restart|reload|status)"

;;

esac

将启动脚本添加到/etc/init.d

中并给予执行权限

Cp  nginx  /etc/init.d

Chmod 755  /etc/init.d/nginx

六.开机自启:

Chkconfig --add /ect/init.d/nginx

二.配置:

1. 目录结构:

cd  /usr/local/nginx/

ls

A.重要目录:

Html  用来存放网站项目目录的文件夹

Logs  日志文件夹

以  _temp结尾的都是相对应的临时文件夹

B.重要的文件:

Mime.types   定义文件格式的配置文件

Nginx    Nginx的二进制文件

Nginx.conf  Nginx配置文件

Nginx.pid  运行起来后会产生此文件存放pid

以 .default结尾  相应配置文件的模版文件

2. 配置文件基本结构:

#全局配置项

....

...

...

#网站项目配置项

http{

#网站项目全局配置项

....

....

#每个项目配置项

Server {

...

....

}

Server {

...

...

}

}

3. 配置项:

worker_processes  worker进程数,根据

cpu

核心数,一般为4或8

error_log  错误日志存放位置

Pid  Nginx运行起来后pid文件存放位置

worker_connections最大连接数一般稍微小于操作系统最大打开句柄数(可设为65535)

include  mime.types  使用mine定义的文件格式

log_format   日志格式

Sendfile  文件传输

gzip  on  gzip压缩

Listen   监听端口

server_name主机名,域名

Root   网站根目录,相对与Nginx 启动文件的目录

Index  主页文件

keepalive_timeout保持链接,超过此时间断开用户链接

相关文章

  • [Docker] Docker 之 Nginx环境搭建

    Docker 之 Nginx环境搭建 Nginx 安装教程 Linux 环境 Linux 中安装 安装编译工具及库...

  • 测试环境部署

    安装Nginx环境(linux) linux环境 下载依赖包 安装nginx需要先将官网下载的源码进行编译,编译依...

  • lnmp的搭建

    lnmp = linux + nginx + mysql + php 1.首先安装nginx(yum安装和编译安装...

  • linux安装nginx

    linux安装nginx gcc安装 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如...

  • 配置nginx和tomcat负载均衡/反向代理

    1. 编辑nginx/conf/nginx.conf 关于nginx的安装,请查看【Linux编译安装Nginx】...

  • Nginx

    Nginx的编译安装(Linux) Nginx部署 Nginx的架构 nginx进程管理:信号

  • nginx的启动,停止,和重启

    nginx 的安装请参照linux安装编译好的nginx 启动 停止 重启

  • Nginx安装

    安装nginx需要的linux环境: 下载nginx 编译安装 使用nginx代理 ,修改配置文件 启动nginx...

  • nginx安装

    进入nginx下载网站: 下载地址 一、Linux安装: Linux安装Nginx需要自行编译,依赖一些库:rcr...

  • PHP 开发环境,源代码安装 LNMP

    源码编译安装 LNMP 环境 LNMP(Linux, Nginx, Mysql, PHP) 源码编译安装,需要用到...

网友评论

    本文标题:Linux编译安装Nginx

    本文链接:https://www.haomeiwen.com/subject/cebdsttx.html