一、服务部署

1、预处理

安装CentOS ,配置hosts、静态IP、设置必要的安全参数等(略)

1-1、系统环境
[root@vnx ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@vnx ~]#
uname -r 2.6.32-696.el6.x86_64 [root@vnx ~]# uname -m x86_64
1-2、检查依赖
[root@vnx ~]# rpm -qa gcc gcc-c++ [root@vnx ~]# rpm -qa pcre-devel pcre
[root@vnx~]# rpm -qa zlib zlib-devel [root@vnx ~]# rpm -qa openssl openssl-devel
1-3、安装依赖
[root@vnx ~]# yum -y install gcc gcc-c++ [root@vnx ~]# yum -y install pcre-
devel pcre [root@vnx~]# yum -y install zlib zlib-devel [root@vnx ~]# yum -y
install openssl openssl-devel
模块说明:

  Nginx 是 C语言 开发,安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

  PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的
http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre
开发的一个二次开发库。nginx也需要此库。

  zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装
zlib 库。

  OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL
协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在
Centos 安装 OpenSSL 库。

摘自:centos7安装Nginx - 极光天际 - 博客园  https://www.cnblogs.com/kaid/p/7640723.html
<https://www.cnblogs.com/kaid/p/7640723.html>

1-4、创建Nginx用户
[root@vnx ~]# useradd nginx -s /sbin/nologin -M
2、下载、解压、编译、安装
[root@vnx ~]# wget --no-check-certificate https://
nginx.org/download/nginx-1.14.0.tar.gz [root@vnx ~]# mkdir -p /home/tools
[root@vnx~]# tar -zxf nginx-1.14.0.tar.gz -C /home/tools/ [root@vnx ~]# cd
/home/tools/nginx-1.14.0/ [root@vnx nginx-1.14.0]# ./configure --user=nginx
--group=nginx --prefix=/app/nginx-1.14.0/ --with-http_stub_status_module --with-
http_ssl_module [root@vnx nginx-1.14.0]# make && make install [root@vnx nginx-
1.14.0]# ln -s /app/nginx-1.14.0/ /app/nginx
3、安装结果检查

3-1、验证,查看目录情况、检查配置文件语法
[root@vnx nginx-1.14.0]# tree -d /app/ /app/ ├── nginx -> /app/nginx-1.14.0/
└── nginx-1.14.0 ├── conf ├── html ├── logs └── sbin [root@vnx nginx-1.14.0]#
/app/nginx/sbin/nginx -t nginx: the configuration file /app/nginx-1.14.0//
conf/nginx.conf syntax is ok nginx: configuration file /app/nginx-1.14.0//
conf/nginx.conf test is successful
3-2、启动,检查端口等检查启动结果
[root@vnx nginx-1.14.0]# /app/nginx/sbin/nginx [root@vnx nginx-1.14.0]# lsof
-i :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 51611 root 6u
IPv4126537 0t0 TCP *:http (LISTEN) nginx 51612 nginx 6u IPv4 126537 0t0 TCP *
:http (LISTEN) [root@vnx nginx-1.14.0]# netstat -lnt | grep 80 tcp 0 0 0.0.0.0:
80 0.0.0.0:* LISTEN [root@vnx nginx-1.14.0]# [root@vnx home]# wget 127.0.0.1
[root@vnx nginx-1.14.0]# curl 127.0.0.1
 二、基于域名的虚拟主机配置

1、编辑hosts映射
[root@vnx nginx]# vim /etc/hosts [root@vnx nginx]# tail -1 /etc/hosts 192.168.
220.129 vnx www.vnx.com blog.vnx.com bbs.vnx.com
2、拷贝、编辑配置文件
[root@vnx nginx]# diff conf/nginx.conf conf/nginx.conf.default [root@vnx
nginx]#egrep -v "#|^$" conf/nginx.conf.default >conf/nginx.conf [root@vnx
nginx]# vim conf/nginx.conf [root@vnx nginx]# cat conf/nginx.conf
worker_processes1; events { worker_connections 1024; } http { include
mime.types; default_type application/octet-stream; sendfile on;
keepalive_timeout65; server { listen 80; server_name www.vnx.com; location / {
root html/www; index index.html index.htm; } } }
3、静态页模拟网站首页
[root@vnx nginx]# mkdir /app/nginx/html/www -p [root@vnx nginx]# echo "
http://www.vnx.com" > /app/nginx/html/www/index.html [root@vnx nginx]# cat
../html/www/index.html http://www.vnx.com
4、检查、重载配置文件
[root@vnx nginx]# ./sbin/nginx -t nginx: the configuration file /app/nginx-1.14
.0//conf/nginx.conf syntax is ok nginx: configuration file /app/nginx-1.14.0//
conf/nginx.conf test is successful [root@vnx nginx]# ./sbin/nginx -s reload
5、检查nginx启动情况、访问情况
[root@vnx www]# ps -ef | grep nginx root 51797 1 0 04:51 ? 00:00:00 nginx:
master process ./sbin/nginx nginx 51877 51797 0 05:01 ? 00:00:00 nginx: worker
process root51912 48379 0 05:11 pts/1 00:00:00 grep nginx [root@vnx www]#
[root@vnx www]# curl www.vnx.com http://www.vnx.com
 

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信