nginx安装
下载nginx,http://nginx.org/en/download.html
下载版本:http://nginx.org/download/nginx-1.12.2.tar.gz
放在服务器上,解压
[root@StudentECSLJM local]# cd nginx-1.12.2
[root@StudentECSLJM nginx-1.12.2]# ll
total 724
drwxr-xr-x 6 yh cat 4096 Feb 3 11:12 auto
-rw-r--r-- 1 yh cat 278202 Oct 17 2017 CHANGES
-rw-r--r-- 1 yh cat 423948 Oct 17 2017 CHANGES.ru
drwxr-xr-x 2 yh cat 4096 Feb 3 11:12 conf
-rwxr-xr-x 1 yh cat 2481 Oct 17 2017 configure
drwxr-xr-x 4 yh cat 4096 Feb 3 11:12 contrib
drwxr-xr-x 2 yh cat 4096 Feb 3 11:12 html
-rw-r--r-- 1 yh cat 1397 Oct 17 2017 LICENSE
drwxr-xr-x 2 yh cat 4096 Feb 3 11:12 man
-rw-r--r-- 1 yh cat 49 Oct 17 2017 README
drwxr-xr-x 9 yh cat 4096 Feb 3 11:12 src
测试是否能安装:
[root@StudentECSLJM nginx-1.12.2]# ./configure --prefix=/usr/local/nginx
报错:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
缺少正则表达式库
安装正则表达式库
[root@StudentECSLJM nginx-1.12.2]# yum install pcre
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
.
.
.
Updated:
pcre.x86_64 0:8.32-17.el7
Complete!
测试仍然不通过,
安装正则表达式扩展库
[root@StudentECSLJM nginx-1.12.2]# yum install pcre-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
...
Installed:
pcre-devel.x86_64 0:8.32-17.el7
Complete!
测试:
缺少zip库
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
[root@StudentECSLJM nginx-1.12.2]# yum install -y zlib
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
[root@StudentECSLJM nginx-1.12.2]# yum install -y zlib-devel
.....
Running transaction
Installing : zlib-devel-1.2.7-18.el7.x86_64 1/1
Verifying : zlib-devel-1.2.7-18.el7.x86_64 1/1
Installed:
zlib-devel.x86_64 0:1.2.7-18.el7
Complete!
可以编译安装的标志
[root@StudentECSLJM nginx-1.12.2]# ./configure --prefix=/usr/local/nginx
.....
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
[root@StudentECSLJM nginx-1.12.2]#
编译和安装
[root@StudentECSLJM nginx-1.12.2]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/usr/local/nginx-1.12.2'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
.....
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/usr/local/nginx-1.12.2'
[root@StudentECSLJM nginx-1.12.2]# ll /usr/local/nginx
total 16
drwxr-xr-x 2 root root 4096 Feb 3 16:08 conf
drwxr-xr-x 2 root root 4096 Feb 3 16:08 html
drwxr-xr-x 2 root root 4096 Feb 3 16:08 logs
drwxr-xr-x 2 root root 4096 Feb 3 16:08 sbin
[root@StudentECSLJM nginx-1.12.2]#
启动
[root@StudentECSLJM nginx-1.12.2]# cd ../nginx
[root@StudentECSLJM nginx]# ./sbin/nginx
[root@StudentECSLJM nginx]# ps -aux | grep nginx
root 9830 0.0 0.0 20480 604 ? Ss 16:11 0:00 nginx: master process ./sbin/nginx
nobody 9831 0.0 0.0 20924 1332 ? S 16:11 0:00 nginx: worker process
root 9840 0.0 0.0 112648 968 pts/0 R+ 16:11 0:00 grep --color=auto nginx
[root@StudentECSLJM nginx]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:32000 127.0.0.1:31000 ESTABLISHED
tcp 0 52 172.18.235.13:22 171.114.138.204:55703 ESTABLISHED
tcp 0 0 172.18.235.13:22 171.114.138.204:55171 ESTABLISHED
tcp 0 0 172.18.235.13:58902 100.100.30.25:80 ESTABLISHED
tcp 0 0 127.0.0.1:31000 127.0.0.1:32000 ESTABLISHED
tcp6 0 0 :::3306 :::* LISTEN