nginx 二进制安装

  • Nginx的安装方法

1:yum安装

默认是1.6版本,且在epel源中

2:源码包编译安装

源码下载:http://nginx.org/en/download.html,下载1.8稳定版本

3:RPM包安装

RPM包下载:http://nginx.org/packages/centos/7/x86_64/

  • 编译时候公网提供编译选项

./configure \

--prefix=/usr/local

--sbin-path=/usr/sbin/nginx

--conf-path=/etc/nginx/nginx.conf

--error-log-path=/var/log/nginx/error.log

--http-log-path=/var/log/nginx/access.log

--pid-path=/var/run/nginx.pid

--lock-path=/var/run/nginx.lock

--http-client-body-temp-path=/var/cache/nginx/client_temp

--http-proxy-temp-path=/var/cache/nginx/proxy_temp

--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp

--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp

--http-scgi-temp-path=/var/cache/nginx/scgi_temp

--user=nginx

--group=nginx

--with-http_ssl_module

--with-http_realip_module

--with-http_addition_module

--with-http_sub_module

--with-http_dav_module

--with-http_flv_module

--with-http_mp4_module

--with-http_gunzip_module

--with-http_gzip_static_module

--with-http_random_index_module

--with-http_secure_link_module

--with-http_stub_status_module

--with-http_auth_request_module

--with-threads

--with-stream

--with-stream_ssl_module

--with-http_slice_module

--with-mail

--with-mail_ssl_module

--with-file-aio

--with-http_v2_module

--with-ipv6

  • 常用的编译选项(先添加Nginx用户和Nginx组,且安装development tools 和 server platform development pcre-devel openssl-devel zlib-devel)

./configure --prefix=/usr/local/nginx1.8 --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_gzip_static_module --with-debug --with-http_stub_status_module

make && make install 编译安装

  • 编译安装完成后启动Nginx、已经Nginx的常用命令讲解

(1)(在启动之前,先将命令添加到环境变量里面,再做一个软连接)

ln -sv /usr/local/nginx1.8 /usr/local/nginx

vi /etc/profile.d/nginx.sh 添加

export PATH=/usr/local/nginx/sbin:$PATH

. /etc/profile.d/nginx.sh

(2)启动Nginx

nginx

(3)查看nginx客户端程序的帮助

nginx -h

  • 编写Nginx的service脚本文件,让其开机自启

(1)vi /etc/rc.d/init.d/nginx 添加

#! /bin/bash

# chkconfig: - 85 15

PATH=/usr/local/nginx

DESC="nginx daemon"

NAME=nginx

DAEMON=$PATH/sbin/$NAME

CONFIGFILE=/etc/nginx/nginx.conf

PIDFILE=/var/run/nginx/nginx.pid

SCRIPTNAME=/etc/init.d/$NAME

set -e

[ -x "$DAEMON" ] || exit 0

do_start() {

$DAEMON -c $CONFIGFILE || echo -n "nginx already running"

}

do_stop() {

$DAEMON -s stop || echo -n "nginx not running"

}

do_reload() {

$DAEMON -s reload || echo -n "nginx can't reload"

}

case "$1" in

start)

echo -n "Starting $DESC: $NAME"

do_start

echo "."

;;

stop)

echo -n "Stopping $DESC: $NAME"

do_stop

echo "."

;;

reload|graceful)

echo -n "Reloading $DESC configuration..."

do_reload

echo "."

;;

restart)

echo -n "Restarting $DESC: $NAME"

do_stop

do_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2

exit 3

;;

esac

exit 0

(2)chmod +x /etc/rc.d/init.d/nginx

(3)chkconfig --add nginx

(4)chkconfig --level 35 nginx on

(5)chkconfig --list