安装nginx

需求:需要在服务器安装nginx
系统:centos7.X
nginx版本:1.9.9

一、下载安装包

1
2
wget http://nginx.org/download/nginx-1.9.9.tar.gz //下载需要用的版本

二、解压

1
tar -zxvf nginx-1.9.9.tar.gz -C /opt/ //解压到你想放的地方 如果没有特殊需求  可以直接解压到/usr/local

三、下载依赖的库文件

1
2
3
4
5
6
7
yum install pcre

yum install pcre-devel

yum install zlib

yum install zlib-devel

四、进行configure配置

1
2
cd /opt/nginx-1.9.9/
./configure --prefix=/opt/nginx //(--prefix=...后是最后编译安装的位置)

执行后会出现以下内容,然后可以进行下一步

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
checking for sha1 in system OpenSSL crypto library ... not found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

  nginx path prefix: "/opt/nginx"
  nginx binary file: "/opt/nginx/sbin/nginx"
  nginx configuration prefix: "/opt/nginx/conf"
  nginx configuration file: "/opt/nginx/conf/nginx.conf"
  nginx pid file: "/opt/nginx/logs/nginx.pid"
  nginx error log file: "/opt/nginx/logs/error.log"
  nginx http access log file: "/opt/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"

五、编译安装

1
make && make install

出现以下内容说明安装成功

1
2
3
4
5
6
7

cp conf/nginx.conf '/opt/nginx/conf/nginx.conf.default'
test -d '/opt/nginx/logs' 		|| mkdir -p '/opt/nginx/logs'
test -d '/opt/nginx/logs' || 		mkdir -p '/opt/nginx/logs'
test -d '/opt/nginx/html' 		|| cp -R html '/opt/nginx'
test -d '/opt/nginx/logs' || 		mkdir -p '/opt/nginx/logs'
make[1]: 离开目录“/opt/nginx-1.9.9”

六、启动Nginx

1
2
cd /opt/nginx/
/opt/nginx/sbin/nginx  //无参数启动 (-s  stop)关闭    (-s reload)重启

7、查看

1
2
3
4
5
6
7
8
9
#查看是否成功启动
[root@k8s-77-189 sbin]# ps -ef | grep nginx
root      3984 27221  0 19:21 pts/2    00:00:00 grep --color=auto nginx
root     30101     1  0 18:37 ?        00:00:00 nginx: master process ./nginx
nobody   30102 30101  0 18:37 ?        00:00:00 nginx: worker process
[root@k8s-77-189 sbin]# lsof -i:80
COMMAND   PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nginx   30101   root    6u  IPv4 6857072      0t0  TCP *:http (LISTEN)
nginx   30102 nobody    6u  IPv4 6857072      0t0  TCP *:http (LISTEN)

成功的话 浏览器访问能看到Welcome to nginx!的页面(http://ip:80)