商城系统网站模板,合肥网站推广培训,安徽省建筑信息平台,无锡百姓网免费发布信息网一、Nginx的优势
nginx是一个高性能的HTTP和反向代理服务器#xff0c;也是一个SMTP#xff08;邮局#xff09;服务器。
Nginx的web优势#xff1a;IO多路复用#xff0c;时分多路复用#xff0c;频分多路复用 高并发#xff0c;IO多路复用#xff0c;epoll#xf…一、Nginx的优势
nginx是一个高性能的HTTP和反向代理服务器也是一个SMTP邮局服务器。
Nginx的web优势IO多路复用时分多路复用频分多路复用 高并发IO多路复用epoll异步非阻塞
IO多路复用理论方法
1.第一种方法最传统的多线程并发模型没进来一个新的I/O六会分配一个新的进程管理
2.第二种方法I/O多路复用耽搁县城通过记录跟踪每个I/O六的状态来同时管理多个I/O流发明他的原因是尽量多个提高服务器的吞吐能力在同一个线程里面通过拨开关的方式来同时传输多个I/O流
IO多路复用技术类型
select
poll
epoll特点异步非阻塞
二、HTTP协议详解
三、Nginx部署Yum
1.官网链接 http://www.nginx.org 2.nginx版本类型 Mainline version:主线版即开发版Stable version最新稳定版生产环境上建议使用的版本Legacy versions遗留的老版本的稳定版 3.配置yum源
下载压缩包 安装nginx文档 4.装环境问题 getenforce systemctl status firewalld yum -y install nginx systemctl start nginx systemctl enable nginx nginx -V 四、Nginx配置文件 rpm -ql nginx 查看所有文件 /etc/logrotate.d/nginx日志轮转/etc/nginx/etc/nginx/conf.d子配置文件/etc/nginx/conf.d/default.conf默认网站配置文件/etc/nginx/fastcgi_params动态网站模块文件-pythonphp所需的相关变量/etc/nginx/mime.types文件关联程序网站文件类型和相关处理程序/etc/nginx/modules模块文件夹第三方模块/etc/nginx/nginx.conf主配置文件/etc/nginx/scgi_params动态网站模块文件-pythonphp所需的相关变量/etc/nginx/uwsgi_params动态网站模块文件-pythonphp所需的相关变量/usr/lib/systemd/system/nginx-debug.servicengnix调试程序启动脚本/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.24.0/usr/share/doc/nginx-1.24.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 缓存/var/log/nginx日志文件
五、Nginx编译参数 ngnix -V nginx version: nginx/1.24.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:配置参数 configure --help 查询帮助--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程序id--lock-path/var/run/nginx.lock所路径防止重复启动nginx--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_tempphp缓存--http-uwsgi-temp-path/var/cache/nginx/uwsgi_temppython缓存--http-scgi-temp-path/var/cache/nginx/scgi_temp--with-compat启动动态模块兼容--usernginx用户--groupnginx组--with-file-aio使用nginx的aio特性会大大提高性能--with-threads多线程模块--with-http_addition_module响应之前或者之后追加文本内容比如像在站点底部追加一个js广告或者新的css样式--with-http_auth_request_module认证模块--with-http_dav_module增加上传PUT,DELETE,MKCOL创建集合COPY,MOVE方法默认情况下为关闭--with-http_flv_modulenginx添加mp4flv视频支持模块--with-http_gunzip_module压缩模块--with-http_gzip_static_module--with-http_mp4_module多媒体模块--with-http_random_index_module--with-http_realip_modulenginx获取真实ip模块--with-http_secure_link_modulenginx安全下载模块--with-http_slice_modulenginx中文文档 --with-http_ssl_module安全模块--with-http_stub_status_module访问状态--with-http_sub_modulenginx替换网站响应内容--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-optcpu优化参数--param--with-ld-opt
六、Nginx基本配置
1.观察主配置文件
1.1分类
1.CoreModule模块进程数等 全局/核心模块配置影响nginx全局的指令一般有运行nginx服务器的用户组nginx进程pid存放位置日志存放路径配置文件引入允许生成worker process数等
2.EventsModule 事件驱动模块工作模式 events块配置影响nginx服务期货与用户的网络连接有每个进程的最大连接数选取哪种事件驱动模型处理连接请求是否需同时接受多个网络连接开启多个网络连接序列化等
nginx优化可以改变worker_process为cpu数量和worker_connections最大连接数
3.HttpCoreModule http内核模块文档程序类型配置文件 default_type application/octet-stream; 字节流处理方式
http模块可以嵌套多个server配置代理缓存日志定义等绝大多数功能和第三方模块的配置如文件引入mime-type定义日子自定义是否使用sendfile传输文件连接超时时间单连接请求数等
4.server块配置虚拟主机的相关参数一个http中可以有多个server
5.location配置请求的路由以及各种页面的处理情况
1.2vim /etc/nginx/nginx.conf
2.观察默认虚拟主机配置文件 vim /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 Apaches document root # concurs with nginxs one # #location ~ /\.ht { # deny all; #} } 3.启动一个新的虚拟主机
3.1vim /etc/nginx/conf.d/xuleilinux.conf 在nginx上启动一个独立的网站 server { listen 80; server_name xuleilinux.com; location / { root /xuleilinux; index index.html; } } mkdir /xuleiLinux echo meinanzi /xuleilinux/index.html 3.2.重启服务 systemctl restart nginx 3.3.域名解析和访问 vim /etc/hosts 192.168.64.139 xuleilinux.com elink xuleilinux.com 出现meinanzi成功 按q退出 七、Nginx日志Log
1.日志配置
1.1日志模块
官方文档 http://nginx.org/en 日志模块的名称ngx_http_log_module
1.2相关指令
log_format日志格式access_logerror_logopen_log_file_cache
1.3日志的格式和命令----log_format
1.3.1简介
Nginx又非常灵活的日志记录模式每个级别的配置可以有各自独立的访问日志日志格式通过log_format命令定义
1.3.2语法 1.3.3默认值 1.3.4环境
Context:http context
1.3.5定义设置位置 vim /etc/nginx/nginx.conf 日志部分配置 日志格式允许包含的变量
$remote_addr远程地址记录客户端ip地址$remote_user远程用户记录客户端用户名称[$time_local]本地时间服务器自身时间$request请求记录请求的url和http协议$status状态,请求状态$body_bytes_sent发送给客户端的字节数不包括响应头的大小$http_referer记录那个页面链接访问过来的超链接$http_user_agent记录客户端浏览器相关信息$http_x_forwarded_for代理ipold
1.4访问日志和错误日志
access_log
error_log
个性化404
1.修改主配置文件 server { listen 80; server_name xuleilinux.com; location / { root /xuleilinux; index index.html; } error_page 404 /404.html; location /404.html { root /xuleilinux; } } 重启nginx systemctl restart nginx 2.创建错误反馈页面 vim /xuleilinux/404.html 3.访问
访问不存在的页面 4.查看404日志
1.5日志缓存
大量访问到来时对于每一条日志记录都将是先打开文件在写入日志然后关闭占用系统的io与业务无关可以使用open_log_file_cache来设 2.日志轮转/切割
前言
Nginx安装回默认启动日志轮转 rpm -ql nginx | grep log /etc/logrotate.d/nginx /var/log/nginx 3.日志分析
八、Nginx WEB模块
1.连接状态 stub_status_module 1.1.目的展示用户和nginx链接数量信息
1.2.查询模块是否安装 nginx -V 21 | grep stub_status 1.3.启动状态模块
1.3.1访问默认站点的状态模块注意错误验证 http://192.168.64.139/nginx_status 未启用404 1.3.2配置状态模块 vim /etc/nginx/conf.d/default.conf server{ location /nginx_status{ stub_status; allow all; } } 启用改模块 1.3.3重启服务再次访问 systemctl restart nginx 观察连接数和请求数 2.随机主页
3.替换模块
4.文件读取
5.文件压缩
6.页面缓存
7.防盗链 九、Nginx访问限制
十、访问控制