Nginx(“engine x”)是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。
在高连接并发的情况下,Nginx是Apache服务器不错的替代品。
Nginx 安装
系统平台:CentOS release 6.6 (Final) 64位。
一、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
[root@linux1 ~]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Setting up Install Process
Package zlib-1.2.3-29.el6.x86_64 already installed and latest version
Package gcc-c++-4.4.7-23.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package libtool.x86_64 0:2.2.6-15.5.el6 will be installed
--> Processing Dependency: automake >= 1.4 for package: libtool-2.2.6-15.5.el6.x86_64
--> Processing Dependency: autoconf >= 2.58 for package: libtool-2.2.6-15.5.el6.x86_64
---> Package make.x86_64 1:3.81-20.el6 will be updated
---> Package make.x86_64 1:3.81-23.el6 will be an update
---> Package openssl.x86_64 0:1.0.1e-15.el6 will be updated
---> Package openssl.x86_64 0:1.0.1e-58.el6_10 will be an update
---> Package openssl-devel.x86_64 0:1.0.1e-58.el6_10 will be installed
--> Processing Dependency: krb5-devel for package: openssl-devel-1.0.1e-58.el6_10.x86_64
---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be installed
--> Running transaction check
---> Package autoconf.noarch 0:2.63-5.1.el6 will be installed
--> Processing Dependency: perl >= 5.005_03 for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl >= 5.005 for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl >= 5.000 for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(vars) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(strict) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(Text::ParseWords) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(POSIX) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(IO::File) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(Getopt::Long) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(File::stat) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(File::Spec) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(File::Path) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(File::Find) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(File::Copy) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(File::Compare) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(File::Basename) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(Exporter) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(Errno) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(DynaLoader) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(Data::Dumper) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(Cwd) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl(Carp) for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: /usr/bin/perl for package: autoconf-2.63-5.1.el6.noarch
---> Package automake.noarch 0:1.11.1-4.el6 will be installed
---> Package krb5-devel.x86_64 0:1.10.3-65.el6 will be installed
--> Processing Dependency: libkadm5(x86-64) = 1.10.3-65.el6 for package: krb5-devel-1.10.3-65.el6.x86_64
--> Processing Dependency: krb5-libs = 1.10.3-65.el6 for package: krb5-devel-1.10.3-65.el6.x86_64
--> Processing Dependency: libselinux-devel for package: krb5-devel-1.10.3-65.el6.x86_64
--> Processing Dependency: libcom_err-devel for package: krb5-devel-1.10.3-65.el6.x86_64
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.10.3-65.el6.x86_64
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.4-5.el6 will be installed
--> Processing Dependency: keyutils-libs = 1.4-5.el6 for package: keyutils-libs-devel-1.4-5.el6.x86_64
---> Package krb5-libs.x86_64 0:1.10.3-10.el6_4.6 will be updated
---> Package krb5-libs.x86_64 0:1.10.3-65.el6 will be an update
---> Package libcom_err-devel.x86_64 0:1.41.12-24.el6 will be installed
--> Processing Dependency: libcom_err = 1.41.12-24.el6 for package: libcom_err-devel-1.41.12-24.el6.x86_64
---> Package libkadm5.x86_64 0:1.10.3-65.el6 will be installed
---> Package libselinux-devel.x86_64 0:2.0.94-7.el6 will be installed
--> Processing Dependency: libselinux = 2.0.94-7.el6 for package: libselinux-devel-2.0.94-7.el6.x86_64
--> Processing Dependency: libsepol-devel >= 2.0.32-1 for package: libselinux-devel-2.0.94-7.el6.x86_64
--> Processing Dependency: pkgconfig(libsepol) for package: libselinux-devel-2.0.94-7.el6.x86_64
---> Package perl.x86_64 4:5.10.1-144.el6 will be installed
--> Processing Dependency: perl-libs = 4:5.10.1-144.el6 for package: 4:perl-5.10.1-144.el6.x86_64
--> Processing Dependency: perl-libs for package: 4:perl-5.10.1-144.el6.x86_64
--> Processing Dependency: perl(version) for package: 4:perl-5.10.1-144.el6.x86_64
--> Processing Dependency: perl(Pod::Simple) for package: 4:perl-5.10.1-144.el6.x86_64
--> Processing Dependency: perl(Module::Pluggable) for package: 4:perl-5.10.1-144.el6.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.10.1-144.el6.x86_64
--> Running transaction check
---> Package keyutils-libs.x86_64 0:1.4-4.el6 will be updated
---> Package keyutils-libs.x86_64 0:1.4-5.el6 will be an update
---> Package libcom_err.x86_64 0:1.41.12-18.el6 will be updated
--> Processing Dependency: libcom_err = 1.41.12-18.el6 for package: e2fsprogs-libs-1.41.12-18.el6.x86_64
--> Processing Dependency: libcom_err = 1.41.12-18.el6 for package: libss-1.41.12-18.el6.x86_64
--> Processing Dependency: libcom_err = 1.41.12-18.el6 for package: e2fsprogs-1.41.12-18.el6.x86_64
---> Package libcom_err.x86_64 0:1.41.12-24.el6 will be an update
---> Package libselinux.x86_64 0:2.0.94-5.3.el6_4.1 will be updated
--> Processing Dependency: libselinux = 2.0.94-5.3.el6_4.1 for package: libselinux-utils-2.0.94-5.3.el6_4.1.x86_64
---> Package libselinux.x86_64 0:2.0.94-7.el6 will be an update
---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 will be installed
---> Package perl-Module-Pluggable.x86_64 1:3.90-144.el6 will be installed
---> Package perl-Pod-Simple.x86_64 1:3.13-144.el6 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.13-144.el6.x86_64
---> Package perl-libs.x86_64 4:5.10.1-144.el6 will be installed
---> Package perl-version.x86_64 3:0.77-144.el6 will be installed
--> Running transaction check
---> Package e2fsprogs.x86_64 0:1.41.12-18.el6 will be updated
---> Package e2fsprogs.x86_64 0:1.41.12-24.el6 will be an update
---> Package e2fsprogs-libs.x86_64 0:1.41.12-18.el6 will be updated
---> Package e2fsprogs-libs.x86_64 0:1.41.12-24.el6 will be an update
---> Package libselinux-utils.x86_64 0:2.0.94-5.3.el6_4.1 will be updated
---> Package libselinux-utils.x86_64 0:2.0.94-7.el6 will be an update
---> Package libss.x86_64 0:1.41.12-18.el6 will be updated
---> Package libss.x86_64 0:1.41.12-24.el6 will be an update
---> Package perl-Pod-Escapes.x86_64 1:1.04-144.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================
Package Arch Version Repository
Size
==============================================================
Installing:
libtool x86_64 2.2.6-15.5.el6 base 564 k
openssl-devel x86_64 1.0.1e-58.el6_10 updates 1.2 M
zlib-devel x86_64 1.2.3-29.el6 base 44 k
Updating:
make x86_64 1:3.81-23.el6 base 389 k
openssl x86_64 1.0.1e-58.el6_10 updates 1.5 M
Installing for dependencies:
autoconf noarch 2.63-5.1.el6 base 781 k
automake noarch 1.11.1-4.el6 base 550 k
keyutils-libs-devel x86_64 1.4-5.el6 base 29 k
krb5-devel x86_64 1.10.3-65.el6 base 504 k
libcom_err-devel x86_64 1.41.12-24.el6 base 33 k
libkadm5 x86_64 1.10.3-65.el6 base 143 k
libselinux-devel x86_64 2.0.94-7.el6 base 137 k
libsepol-devel x86_64 2.0.41-4.el6 base 64 k
perl x86_64 4:5.10.1-144.el6 base 10 M
perl-Module-Pluggable x86_64 1:3.90-144.el6 base 41 k
perl-Pod-Escapes x86_64 1:1.04-144.el6 base 33 k
perl-Pod-Simple x86_64 1:3.13-144.el6 base 213 k
perl-libs x86_64 4:5.10.1-144.el6 base 579 k
perl-version x86_64 3:0.77-144.el6 base 52 k
Updating for dependencies:
e2fsprogs x86_64 1.41.12-24.el6 base 554 k
e2fsprogs-libs x86_64 1.41.12-24.el6 base 121 k
keyutils-libs x86_64 1.4-5.el6 base 20 k
krb5-libs x86_64 1.10.3-65.el6 base 675 k
libcom_err x86_64 1.41.12-24.el6 base 38 k
libselinux x86_64 2.0.94-7.el6 base 109 k
libselinux-utils x86_64 2.0.94-7.el6 base 82 k
libss x86_64 1.41.12-24.el6 base 42 k
Transaction Summary
==============================================================
Install 17 Package(s)
Upgrade 10 Package(s)
Total download size: 19 M
Downloading Packages:
(1/27): autoconf-2.63-5.1.el6.noarch.r | 781 kB 00:00
(2/27): automake-1.11.1-4.el6.noarch.r | 550 kB 00:00
(3/27): e2fsprogs-1.41.12-24.el6.x86_6 | 554 kB 00:00
(4/27): e2fsprogs-libs-1.41.12-24.el6. | 121 kB 00:00
(5/27): keyutils-libs-1.4-5.el6.x86_64 | 20 kB 00:00
(6/27): keyutils-libs-devel-1.4-5.el6. | 29 kB 00:00
(7/27): krb5-devel-1.10.3-65.el6.x86_6 | 504 kB 00:00
(8/27): krb5-libs-1.10.3-65.el6.x86_64 | 675 kB 00:00
(9/27): libcom_err-1.41.12-24.el6.x86_ | 38 kB 00:00
(10/27): libcom_err-devel-1.41.12-24.e | 33 kB 00:00
(11/27): libkadm5-1.10.3-65.el6.x86_64 | 143 kB 00:00
(12/27): libselinux-2.0.94-7.el6.x86_6 | 109 kB 00:00
(13/27): libselinux-devel-2.0.94-7.el6 | 137 kB 00:00
(14/27): libselinux-utils-2.0.94-7.el6 | 82 kB 00:00
(15/27): libsepol-devel-2.0.41-4.el6.x | 64 kB 00:00
(16/27): libss-1.41.12-24.el6.x86_64.r | 42 kB 00:00
(17/27): libtool-2.2.6-15.5.el6.x86_64 | 564 kB 00:00
(18/27): make-3.81-23.el6.x86_64.rpm | 389 kB 00:00
(19/27): openssl-1.0.1e-58.el6_10.x86_ | 1.5 MB 00:01
(20/27): openssl-devel-1.0.1e-58.el6_1 | 1.2 MB 00:00
(21/27): perl-5.10.1-144.el6.x86_64.rp | 10 MB 00:08
(22/27): perl-Module-Pluggable-3.90-14 | 41 kB 00:00
(23/27): perl-Pod-Escapes-1.04-144.el6 | 33 kB 00:00
(24/27): perl-Pod-Simple-3.13-144.el6. | 213 kB 00:00
(25/27): perl-libs-5.10.1-144.el6.x86_ | 579 kB 00:00
(26/27): perl-version-0.77-144.el6.x86 | 52 kB 00:00
(27/27): zlib-devel-1.2.3-29.el6.x86_6 | 44 kB 00:00
--------------------------------------------------------------
Total 1.1 MB/s | 19 MB 00:16
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : libcom_err-1.41.12-24.el6.x86_64 1/37
Updating : libselinux-2.0.94-7.el6.x86_64 2/37
Updating : keyutils-libs-1.4-5.el6.x86_64 3/37
Updating : krb5-libs-1.10.3-65.el6.x86_64 4/37
Installing : libkadm5-1.10.3-65.el6.x86_64 5/37
Installing : keyutils-libs-devel-1.4-5.el6.x86_64 6/37
Updating : e2fsprogs-libs-1.41.12-24.el6.x86_64 7/37
Installing : libcom_err-devel-1.41.12-24.el6.x86_64 8/37
Updating : libss-1.41.12-24.el6.x86_64 9/37
Installing : 1:perl-Pod-Escapes-1.04-144.el6.x86_64 10/37
Installing : 4:perl-libs-5.10.1-144.el6.x86_64 11/37
Installing : 1:perl-Pod-Simple-3.13-144.el6.x86_64 12/37
Installing : 1:perl-Module-Pluggable-3.90-144.el6.x 13/37
Installing : 3:perl-version-0.77-144.el6.x86_64 14/37
Installing : 4:perl-5.10.1-144.el6.x86_64 15/37
Installing : autoconf-2.63-5.1.el6.noarch 16/37
Installing : automake-1.11.1-4.el6.noarch 17/37
Installing : libsepol-devel-2.0.41-4.el6.x86_64 18/37
Installing : libselinux-devel-2.0.94-7.el6.x86_64 19/37
Installing : krb5-devel-1.10.3-65.el6.x86_64 20/37
Updating : 1:make-3.81-23.el6.x86_64 21/37
Updating : openssl-1.0.1e-58.el6_10.x86_64 22/37
Installing : zlib-devel-1.2.3-29.el6.x86_64 23/37
Installing : openssl-devel-1.0.1e-58.el6_10.x86_64 24/37
Installing : libtool-2.2.6-15.5.el6.x86_64 25/37
Updating : e2fsprogs-1.41.12-24.el6.x86_64 26/37
Updating : libselinux-utils-2.0.94-7.el6.x86_64 27/37
Cleanup : e2fsprogs-1.41.12-18.el6.x86_64 28/37
Cleanup : openssl-1.0.1e-15.el6.x86_64 29/37
Cleanup : krb5-libs-1.10.3-10.el6_4.6.x86_64 30/37
Cleanup : e2fsprogs-libs-1.41.12-18.el6.x86_64 31/37
Cleanup : libss-1.41.12-18.el6.x86_64 32/37
Cleanup : libselinux-utils-2.0.94-5.3.el6_4.1.x8 33/37
Cleanup : libselinux-2.0.94-5.3.el6_4.1.x86_64 34/37
Cleanup : libcom_err-1.41.12-18.el6.x86_64 35/37
Cleanup : keyutils-libs-1.4-4.el6.x86_64 36/37
Cleanup : 1:make-3.81-20.el6.x86_64 37/37
Verifying : 3:perl-version-0.77-144.el6.x86_64 1/37
Verifying : 4:perl-5.10.1-144.el6.x86_64 2/37
Verifying : krb5-devel-1.10.3-65.el6.x86_64 3/37
Verifying : krb5-libs-1.10.3-65.el6.x86_64 4/37
Verifying : e2fsprogs-libs-1.41.12-24.el6.x86_64 5/37
Verifying : automake-1.11.1-4.el6.noarch 6/37
Verifying : libcom_err-devel-1.41.12-24.el6.x86_64 7/37
Verifying : keyutils-libs-devel-1.4-5.el6.x86_64 8/37
Verifying : 4:perl-libs-5.10.1-144.el6.x86_64 9/37
Verifying : libss-1.41.12-24.el6.x86_64 10/37
Verifying : zlib-devel-1.2.3-29.el6.x86_64 11/37
Verifying : 1:perl-Pod-Simple-3.13-144.el6.x86_64 12/37
Verifying : 1:perl-Pod-Escapes-1.04-144.el6.x86_64 13/37
Verifying : libselinux-devel-2.0.94-7.el6.x86_64 14/37
Verifying : keyutils-libs-1.4-5.el6.x86_64 15/37
Verifying : 1:make-3.81-23.el6.x86_64 16/37
Verifying : openssl-1.0.1e-58.el6_10.x86_64 17/37
Verifying : autoconf-2.63-5.1.el6.noarch 18/37
Verifying : 1:perl-Module-Pluggable-3.90-144.el6.x 19/37
Verifying : libcom_err-1.41.12-24.el6.x86_64 20/37
Verifying : libsepol-devel-2.0.41-4.el6.x86_64 21/37
Verifying : openssl-devel-1.0.1e-58.el6_10.x86_64 22/37
Verifying : libselinux-utils-2.0.94-7.el6.x86_64 23/37
Verifying : libkadm5-1.10.3-65.el6.x86_64 24/37
Verifying : libselinux-2.0.94-7.el6.x86_64 25/37
Verifying : libtool-2.2.6-15.5.el6.x86_64 26/37
Verifying : e2fsprogs-1.41.12-24.el6.x86_64 27/37
Verifying : e2fsprogs-1.41.12-18.el6.x86_64 28/37
Verifying : libselinux-2.0.94-5.3.el6_4.1.x86_64 29/37
Verifying : openssl-1.0.1e-15.el6.x86_64 30/37
Verifying : libselinux-utils-2.0.94-5.3.el6_4.1.x8 31/37
Verifying : libcom_err-1.41.12-18.el6.x86_64 32/37
Verifying : e2fsprogs-libs-1.41.12-18.el6.x86_64 33/37
Verifying : 1:make-3.81-20.el6.x86_64 34/37
Verifying : krb5-libs-1.10.3-10.el6_4.6.x86_64 35/37
Verifying : libss-1.41.12-18.el6.x86_64 36/37
Verifying : keyutils-libs-1.4-4.el6.x86_64 37/37
Installed:
libtool.x86_64 0:2.2.6-15.5.el6
openssl-devel.x86_64 0:1.0.1e-58.el6_10
zlib-devel.x86_64 0:1.2.3-29.el6
Dependency Installed:
autoconf.noarch 0:2.63-5.1.el6
automake.noarch 0:1.11.1-4.el6
keyutils-libs-devel.x86_64 0:1.4-5.el6
krb5-devel.x86_64 0:1.10.3-65.el6
libcom_err-devel.x86_64 0:1.41.12-24.el6
libkadm5.x86_64 0:1.10.3-65.el6
libselinux-devel.x86_64 0:2.0.94-7.el6
libsepol-devel.x86_64 0:2.0.41-4.el6
perl.x86_64 4:5.10.1-144.el6
perl-Module-Pluggable.x86_64 1:3.90-144.el6
perl-Pod-Escapes.x86_64 1:1.04-144.el6
perl-Pod-Simple.x86_64 1:3.13-144.el6
perl-libs.x86_64 4:5.10.1-144.el6
perl-version.x86_64 3:0.77-144.el6
Updated:
make.x86_64 1:3.81-23.el6 openssl.x86_64 0:1.0.1e-58.el6_10
Dependency Updated:
e2fsprogs.x86_64 0:1.41.12-24.el6
e2fsprogs-libs.x86_64 0:1.41.12-24.el6
keyutils-libs.x86_64 0:1.4-5.el6
krb5-libs.x86_64 0:1.10.3-65.el6
libcom_err.x86_64 0:1.41.12-24.el6
libselinux.x86_64 0:2.0.94-7.el6
libselinux-utils.x86_64 0:2.0.94-7.el6
libss.x86_64 0:1.41.12-24.el6
Complete!
二、首先要安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
1、下载 PCRE 安装包,下载地址:
http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
如果wget没有安装的话,需要先安装wget,yum -y install wget
[root@linux1 src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
-bash: wget: command not found
[root@linux1 src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
-bash: wget: command not found
[root@linux1 src]# yum -y install wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.12-10.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================
Package Arch Version Repository Size
==============================================================
Installing:
wget x86_64 1.12-10.el6 base 484 k
Transaction Summary
==============================================================
Install 1 Package(s)
Total download size: 484 k
Installed size: 1.8 M
Downloading Packages:
wget-1.12-10.el6.x86_64.rpm | 484 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : wget-1.12-10.el6.x86_64 1/1
Verifying : wget-1.12-10.el6.x86_64 1/1
Installed:
wget.x86_64 0:1.12-10.el6
Complete!
2、解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
3、进入安装包目录
[root@bogon src]# cd pcre-8.35
4、编译安装
[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install
5、查看pcre版本
[root@bogon pcre-8.35]# pcre-config --version
[root@linux1 pcre-8.35]# pcre-config --version
8.35
[root@linux1 pcre-8.35]#
安装 Nginx
1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz
[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
2、解压安装包
[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz
3、进入安装包目录
[root@bogon src]# cd nginx-1.6.2
4、编译安装
[root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@bogon nginx-1.6.2]# make
[root@bogon nginx-1.6.2]# make install
5、查看nginx版本
[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v
到此,nginx安装完成。
[root@linux1 nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v
nginx version: nginx/1.6.2
[root@linux1 nginx-1.6.2]#
Nginx 配置
创建 Nginx 运行使用的用户 www:
[root@bogon conf]# /usr/sbin/groupadd www
[root@bogon conf]# /usr/sbin/useradd -g www www
配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容
[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.conf
```c
user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
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 128k;
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;
#limit_zone crawler $binary_remote_addr 10m;
#下面是server虚拟主机的配置
server
{
listen 80;#监听端口
server_name localhost;#域名
index index.html index.htm index.php;
root /usr/local/webserver/nginx/html;#站点目录
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
location ~ .*\.(js|css)?$
{
expires 15d;
# access_log off;
}
access_log off;
}
}
检查配置文件nginx.conf的正确性命令:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
```c
[root@linux1 nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/webserver/nginx/conf/nginx.conf test is successful
启动 Nginx
Nginx 启动命令如下:
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx
[root@linux1 nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx
[root@linux1 nginx-1.6.2]# ps -ef|grep nginx
root 10663 1 0 10:05 ? 00:00:00 nginx: master process /usr/local/webserver/nginx/sbin/nginx
www 10664 10663 0 10:05 ? 00:00:00 nginx: worker process
root 10666 1160 0 10:05 pts/0 00:00:00 grep nginx
访问站点
从浏览器访问我们配置的站点ip:
Nginx 其他命令
以下包含了 Nginx 常用的几个命令:
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)