linux---集群架构初探(16)Nginx安装、配置文件、模块

Nginx安装

nginx无法直接通过yum安装,需要先进行配置,并且要保证其依赖库已安装完成。

检查依赖项(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库)

安装方法为:yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel

配置文件(参考官网:http://nginx.org/en/linux_packages.html

vim /etc/yum.repos.d/nginx.repo

默认安装的是stable(稳定版),若想安装mainline(主线版),需用管理员进行如下设置:

yum-config-manager --enable nginx-mainline

设置好后,安装:

查看版本

 启动并查看

 启动服务:systemctl start nginx

查看进程:ps -ef | grep nginx

在浏览器中输入服务器IP地址(注意防火墙需允许访问):

 小试牛刀

 vim /etc/nginx/nginx.conf

在http模块内添加:

 重启服务:nginx -s reload

在浏览器输入本服务器ip,会跳转至百度首页。

Nginx配置文件

Nginx主配置文件

  /etc/nginx
  /etc/nginx/nginx.conf
  /etc/nginx/conf.d
  /etc/nginx/conf.d/default.conf

Cgi、FastCgi、Uwcgi配置文件

  /etc/nginx/scgi_params
  /etc/nginx/fastcgi_params
  /etc/nginx/uwsgi_params

Nginx编码转换映射文件
  /etc/nginx/koi-utf
  /etc/nginx/koi-win
  /etc/nginx/win-utf

http协议的Content-Type与扩展名

  /etc/nginx/mime.types

配置系统守护进程管理器

  /usr/lib/systemd/system/nginx.service
  /etc/sysconfig/nginx
  /etc/sysconfig/nginx-debug
  /usr/lib/systemd/system/nginx-debug.service

Nginx日志轮询,日志切割

  /etc/logrotate.d/nginx

Nginx终端管理命令

  /usr/sbin/nginx
  /usr/sbin/nginx-debug

Nginx模块目录

  /etc/nginx/modules
  /usr/lib64/nginx
  /usr/lib64/nginx/modules

Nginx默认站点目录

  /usr/share/nginx
  /usr/share/nginx/html
  /usr/share/nginx/html/50x.html
  /usr/share/nginx/html/index.html

Nginx帮助手册

  /usr/share/doc/nginx-1.18.0
  /usr/share/man/man8/nginx.8.gz
  /var/cache/nginx
  /var/log/nginx
  /usr/share/doc/nginx-1.18.0/COPYRIGHT

Nginx主配置文件/etc/nginx/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块形式组织的,每个区块以一对大括号来表示开始和结束。

Nginx模块

nginx模块主要分为3种:

1.CoreModule  核心模块

2.EventModule  事件驱动模块

3.HttpCoreModule  http内核模块

扩展项:

CoreModule层下可以有Event、HTTP。

HTTP模块层允许有多个server层,server主要用于配置多个网站。

server层允许有多个location,location主要用于定义网站访问路径。

自定义配置文件

1.备份并关闭默认的配置文件

2.创建自定义配置文件

vim pm.conf

注:规范的话,这里的server_name要写对应域名,后面会讲。

语法测试

3.创建目录并上传html代码

4.重启并测试

systemctl reload nginx

 学习回顾--使用ansible批量安装nginx

过程:使用管理服务器m01为web01、web02批量安装nginx,并配置网站

1.配置ansible主机列表文件

2.上传网站文件

3.nginx安装配置文件

4.编写脚本

5.编写playbook

 6.执行

注:这个版本的nginx中/etc/nginx/nginx.conf里有默认的server区块,监听80端口,需要注释掉或者使用别的端口。

posted @ 2020-06-15 05:07  盗哥泡茶去了  阅读(87)  评论(0编辑  收藏  举报