36.Nginx 基础入门篇
1. 简介:
Nginx(engine x)是一个高性能的HTTP(解决C10k的问题)和反向代理服务器,也是一个IMAP/POP3/SWTP服务器。
2. Nginx的web优势:
1)IO多路分复用(单个线程,通过记录跟踪每个I/O流(sock)的状态,来同时管理多个I/O流); 2)时分多路复用; 3)频分多路复用
注意:IO多路分复用技术类型:select,poll,epoll(特点:异步,非阻塞)
3. Nginx部署:
(1)官网链接:http://www.nginx.org
(2)Nginx版本类型:1)Mainline version:主线版,即开发版
2)Stable version:最新稳定版本,生产环境上建议使用的版本
3)Legacy versions:遗留的老版本的稳定版
(3)Linux安装:
此时按照以上官方文档给的步骤进行操作:
[root@Nginx ~]# sudo yum install yum-utils
[root@Nginx ~]# vi /etc/yum.repos.d/nginx.repo #配置镜像源
[root@Nginx ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@Nginx ~]# yum clean all #清除缓存[root@Nginx ~]# yum makecache #重新建立缓存
[root@Nginx ~]# sudo yum install nginx #安装Nginx
[root@Nginx ~]# systemctl stop firewalld
[root@Nginx ~]# systemctl start nginx
[root@Nginx ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@Nginx ~]# nginx -V #查看Nginx版本号
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
(4)测试:(关闭防火墙后,在浏览器输入IP地址)
4. Nginx配置文件:
(1)rpm -ql nginx
/etc/logrotate.d/nginx #日志轮转
/etc/nginx #总配置文件
/etc/nginx/conf.d #子配置文件
/etc/nginx/conf.d/default.conf #默认的网站配置文件
/etc/nginx/fastcgi_params
/etc/nginx/mime.types #文件关联程序(包括 网站文件类型 和 相关处理程序)
/etc/nginx/modules #模块文件夹,第三方模块
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/usr/lib/systemd/system/nginx-debug.service #nginx调试程序启动脚本
/usr/lib/systemd/system/nginx.service #服务脚本
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx #主程序
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.22.0
/usr/share/doc/nginx-1.22.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx #缓存各种(ls /var/cache/nginx/)
/var/log/nginx #日志文件夹(ls /var/log/nginx/)(access.log访问日志 error.log错误日志)
5. Nginx编译参数
(1)nginx -V
[root@Nginx ~]# nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
6. Nginx基本配置
(1)观察主配置文件:/etc/nginx/nginx.conf
分类:1)CoreModule 核心模块:
全局/核心块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。
#cat -n /etc/nginx/nginx.conf12 user nginx;3 worker_processes auto; #开启nginx的数量45 error_log /var/log/nginx/error.log notice; #错误日志所存储的位置6 pid /var/run/nginx.pid; #启动时,创造出来的进程号78
2)EventsModule 事件驱动模块:
events块:配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网络连接,开启多个网络连接序列化等。
9 events {10 worker_connections 1024; #nginx工作可连接用户数11 }1213
3)HttpCoreModule 指http内核模块:
http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。
14 http {15 include /etc/nginx/mime.types;16 default_type application/octet-stream;1718 log_format main '$remote_addr - $remote_user [$time_local] "$request" '19 '$status $body_bytes_sent "$http_referer" '20 '"$http_user_agent" "$http_x_forwarded_for"';2122 access_log /var/log/nginx/access.log main;2324 sendfile on;25 #tcp_nopush on;2627 keepalive_timeout 65;2829 #gzip on;3031 include /etc/nginx/conf.d/*.conf;32 }
4)server块:配置虚拟主机的相关参数,一个http中可以有多个server.
5)location块:配置请求的路由,以及各种页面的处理情况。
(2)观察默认虚拟主机配置文件:/etc/nginx/conf.d/default.conf
server {listen 80; #监听端口server_name localhost; #服务器购买的域名#access_log /var/log/nginx/host.access.log main; #日志location / {root /usr/share/nginx/html; #默认网站目录index index.html index.htm; #默认主页}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html; #默认的错误页面location = /50x.html {root /usr/share/nginx/html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}
}
7. Nginx日志log
36.Nginx 基础入门篇相关推荐
- 云小课|DGC数据开发之基础入门篇
阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要:欢迎来到DGC数据 ...
- 跟着王进老师学开发之Python篇第一季:基础入门篇-王进-专题视频课程
跟着王进老师学开发之Python篇第一季:基础入门篇-2859人已学习 课程介绍 本季课程首先对Python简要介绍,然后演示如何搭建Python的开发环境,以及如何在IDE中调试Py ...
- 《Ansible权威指南 》一 第一篇 Part 1 基础入门篇
本节书摘来自华章出版社<Ansible权威指南 >一书中的第1章,第1.1节,李松涛 魏 巍 甘 捷 著更多章节内容可以访问云栖社区"华章计算机"公众号查看. 第一篇 ...
- linux入门_Linux超详细0基础入门篇(一)
首先要感谢大康老师对我在Linux操作系统上的教导. 今天来讲一下用途广泛的Linux的基础入门教程 仅仅是做入门使用,如果想更加深入的学习那就需要自己做探索了. 本次例子使用的是kali linux ...
- sqlalchemy mysql教程_SQLAlchemy 教程 —— 基础入门篇
SQLAlchemy 教程 -- 基础入门篇 一.课程简介 1.1 实验内容 本课程带领大家使用 SQLAlchemy 连接 MySQL 数据库,创建一个博客应用所需要的数据表,并介绍了使用 SQLA ...
- FPGA基础入门篇(四) 边沿检测电路
FPGA基础入门篇(四)--边沿检测电路 一.边沿检测 边沿检测,就是检测输入信号,或者FPGA内部逻辑信号的跳变,即上升沿或者下降沿的检测.在检测到所需要的边沿后产生一个高电平的脉冲.这在FPGA电 ...
- JAVA中整型常量的长度,Java基础入门篇(三)——Java常量、变量,
Java基础入门篇(三)--Java常量.变量, 一.Java常量 (一)什么是常量 常量指的是在程序中固定不变的值,是不能改变的数据.在Java中,常量包括整型常量.浮点型常量.布尔常量.字符常量等 ...
- 〖Python零基础入门篇㉟〗- 私有函数、私有变量及封装
订阅 Python全栈白宝书-零基础入门篇 可报销!白嫖入口-请点击我.推荐他人订阅,可获取扣除平台费用后的35%收益,文末名片加V! 说明:该文属于 Python全栈白宝书专栏,免费阶段订阅数量43 ...
- EGE基础入门篇(六):基本图形
EGE专栏:EGE专栏 上一篇:EGE基础入门篇(五):窗口简单操作 下一篇:EGE基础入门篇(七):组合图形 一.EGE提供的基本图形 EGE绘制图形相关库函数文档 https://xege.org ...
最新文章
- isinstance函数和@staticmethod用法
- 【HDU 1501】Zipper(记忆化搜索)
- (剑指Offer)面试题1:赋值运算符函数
- laravel 分页
- python中info的用法_Python pandas.DataFrame.info函数方法的使用
- Hexo+GitHub 快速搭建个人博客(二)---- 域名解析
- UVA 694-The Collatz Sequence
- leetcode刷题——415. 字符串相加
- centos7永久修改主机名
- java数组里的索引越界问题、空指针异常问题
- 【PMP】三点估算结合正态分布图
- 音乐计算机研修心得,音乐教师研修总结报告
- 基于FPGA的UART串口通信实验(VHDL语言实现)
- 显示器颜色偏色的排查过程(偏黄、偏红、偏蓝、偏绿等)
- ZYNQ开发系列——双串口打印以及串口波特率设置
- (理财六)贷款用途的分类
- 什么人适合学习嵌入式开发?
- 如何将手机里的文件打印出来?
- 从月薪3千到3万,需要努力多久?
- 初步使用openEuler华为欧拉Linux系统