nginx离线安装
下载地址:https://nginx.org/download/
一、安装编译工具及库文件
[root@VM-20-14-centos ~]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
二、安装 PCRE
[root@VM-20-14-centos ~]# tar -zxvf pcre-8.35.tar.gz
[root@VM-20-14-centos ~]# cd pcre-8.35
[root@VM-20-14-centos pcre-8.35]# ./configure
[root@VM-20-14-centos pcre-8.35]# make && make install
查看pcre版本
[root@VM-20-14-centos pcre-8.35]# pcre-config --version
三、安装 Nginx
[root@VM-20-14-centos ~]# tar -zxvf nginx-1.6.2.tar.gz
[root@VM-20-14-centos nginx-1.6.2]# ./configure
#需要指定安装目录等内容,可添加如下参数
[root@VM-20-14-centos src]# cd nginx-1.6.2
[root@VM-20-14-centos 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@VM-20-14-centos nginx-1.6.2]# make
–prefix=/usr/local/webserver/nginx指定nginx安装路径为/usr/local/webserver/nginx
–with-http_stub_status_module开启stub_status监控模块
–with-http_ssl_module开启nginx-http-ssl模块,为https提供支持,一般使用listen代替,不开启
–with-pcre=/usr/local/src/pcre-8.35指定pcre地址
查看nginx版本
[root@VM-20-14-centos nginx-1.6.2]# cd /usr/local/nginx/sbin/nginx
[root@VM-20-14-centos sbin]# ./nginx -v
启动nginx
[root@VM-20-14-centos sbin]# ./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
docker安装nginx
[root@VM-20-14-centos ~]# docker pull nginx
[root@VM-20-14-centos ~]# docker run --name nginx-test -p 8081:80 -d nginx
#查看docker 镜像进程
[root@VM-20-14-centos ~]# docker ps
[root@VM-20-14-centos ~]# mkdir -p /data/nginx/www /data/nginx/log /data/nginx/conf
[root@VM-20-14-centos ~]# docker cp 容器id:/etc/nginx /data/nginx/conf
[root@VM-20-14-centos ~]# docker stop nginx-test
[root@VM-20-14-centos ~]# docker run --name nginx -p 8081:80 -v /data/nginx/conf/nginx:/etc/nginx -v /data/nginx/log:/var/log/nginx -v /data/nginx/www:/usr/share/nginx/html -d nginx
#查看docker 镜像进程
[root@VM-20-14-centos ~]# docker ps
在~/nginx/www 下创建 index.html
重新访问:localhost:8082