当前位置: 首页 > news >正文

创新的网站建设公司金戈枸橼酸西地那非片

创新的网站建设公司,金戈枸橼酸西地那非片,网站管理规定,WordPress添加图片模块Nginx优化服务和防盗链一、长连接1、修改主配置文件2、测试3、在主配置文件添加4、验证二、Nginx第三方模块1、开源的echo模块2、查看是否成功3、加echo模块步骤4、网页测试验证三、搭建虚拟主机1、编译安装好nginx后,对主配置文件进行修改2、创建文件3、验证四、防…

Nginx优化服务和防盗链

    • 一、长连接
      • 1、修改主配置文件
      • 2、测试
      • 3、在主配置文件添加
      • 4、验证
    • 二、Nginx第三方模块
      • 1、开源的echo模块
      • 2、查看是否成功
      • 3、加echo模块步骤
      • 4、网页测试验证
    • 三、搭建虚拟主机
      • 1、编译安装好nginx后,对主配置文件进行修改
      • 2、创建文件
      • 3、验证
    • 四、防盗链
      • 1、先yum安装nginx,两台机子都要装
      • 2、网页准备
      • 3、Web源主机配置防盗链
    • 五、配置网页压缩
    • 六、日志分割
    • 七、修改Nginx运行的用户和组

一、长连接

长连接是指在一个连接上可以连续发送多个数据包,在连接保持期间,如果没有数据包发送,需 …
短连接是指通讯双方有数据交互时,就建立一个连接,数据发送完成后,则断开此连接,即每次连接只完成一项业务的发送。

1、修改主配置文件

[root@www ~]#vim /apps/nginx/conf/nginx.conf
http {include       mime.types;include       /apps/nginx/conf.d/*.conf;   ##添加这行内容default_type  application/octet-stream;
[root@www ~]#cd /apps/nginx/      ##切换到/apps/nginx/目录
[root@www nginx]#mkdir conf.d   ##创建conf.d文件
[root@www nginx]#cd conf.d/     ##切换到conf.d目录里
[root@www conf.d]#vim pc.conf   ##编辑pc。conf文件
server{listen 80;server_name  www.zhantai.com;root  /data/nginx/pc/;[root@www conf.d]#mkdir -pv /data/nginx/pc/   ##递归创建文件夹
mkdir: 已创建目录 "/data"
mkdir: 已创建目录 "/data/nginx"
mkdir: 已创建目录 "/data/nginx/pc/"[root@www conf.d]#echo pc > /data/nginx/pc/index.html
[root@www conf.d]#tree /data/
/data/
└── nginx└── pc└── index.html2 directories, 1 file
[root@www conf.d]#systemctl restart nginx  ##重启服务

在这里插入图片描述
在这里插入图片描述

2、测试

在另一台机子
[root@localhost ~]# vi /etc/hosts   ##将前面一台机子的IP地址和域名需要写在hosts文件里面
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.130 www.zhantai.com
[root@localhost ~]# curl www.zhantai.com   ##验证出现pc就OK了
pc

在这里插入图片描述

3、在主配置文件添加

[root@www conf.d]#vi pc.confserver{listen 80;server_name  www.zhantai.com;root  /data/nginx/pc/;keepalive_requests 3;keepalive_timeout 60 65;
}
[root@www conf.d]#systemctl restart nginx  ##重启服务
[root@www conf.d]#nginx -s reload    ##重新加载配置

在这里插入图片描述

4、验证

在另一台机子验证
[root@localhost ~]# curl www.zhantai.com -I
HTTP/1.1 200 OK
Server: nginx/1.20.2
Date: Tue, 21 Feb 2023 14:26:36 GMT
Content-Type: text/html
Content-Length: 3
Last-Modified: Tue, 21 Feb 2023 13:50:18 GMT
Connection: keep-alive
Keep-Alive: timeout=65      ###超时时间
ETag: "63f4cc1a-3"
Accept-Ranges: bytes

在这里插入图片描述

二、Nginx第三方模块

1、开源的echo模块

现将代码包上传到/opt目录下,解压
[root@www opt]#cd /opt/   
[root@www opt]#unzip echo-nginx-module-master.zip     #解压
[root@www opt]#cd nginx-1.18.0/
[root@www nginx-1.18.0]#systemctl stop nginx  #编译前先停掉服务,在编译./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/opt/echo-nginx-module-master   #第三方模块make  &&  make install    #重新编译之后就有第三方模块,编译时就可以使用
此代码包下载需要翻墙,方便期间,可以直接到网盘下载:
链接:https://pan.baidu.com/s/1ULiMf3Kc3MWjmrozZu6fQA 
提取码:q94p

在这里插入图片描述

2、查看是否成功

在这里插入图片描述

3、加echo模块步骤

[root@www nginx-1.18.0]#systemctl start nginx
[root@www nginx-1.18.0]#cd /apps/nginx/conf.d/
[root@www conf.d]#vim pc.conf    #进入配置文件添加一下内容location  /hello {default_type   text/html;echo "hello world ";}
}
[root@www conf.d]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@www conf.d]#nginx -s reload

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4、网页测试验证

在这里插入图片描述

三、搭建虚拟主机

1、编译安装好nginx后,对主配置文件进行修改

[root@localhost]# cd /apps/nginx/conf/
[root@www conf]#vim nginx.conf  ##在http模块添加这个内容,在这只能写http子模块,要在主配置文件
include /apps/nginx/conf.d/*.conf;
[root@www nginx]#mkdir conf.d

在这里插入图片描述

2、创建文件

[root@www nginx]#cd conf.d/
[root@www conf.d]#vi pc.conf
server{listen  80;server_name   www.pc.com;root  /data/nginx/pc/;}
[root@www conf.d]#vi m.conf
server{listen  80;server_name   www.m.com;root  /data/nginx/m/;}

在这里插入图片描述
在这里插入图片描述

3、验证

在第二台机子
[root@localhost ~]# vi /etc/hosts
192.168.10.130  www.pc.com   www.m.com
[root@localhost ~]# curl www.pc.com
pc
[root@localhost ~]# curl www.m.com
mobile
[root@localhost ~]#

在这里插入图片描述

四、防盗链

1、先yum安装nginx,两台机子都要装

[root@localhost ~]#yum install -y epel-release    #yum安装nginx
[root@localhost ~]#yum info nginx
[root@localhost ~]#yum install -y nginx
[root@localhost ~]#systemctl restart nginx.service    #重启服务
[root@localhost ~]#cd /usr/share/nginx/html/
[root@localhost html]#vim index.html<html>
<body>
<h1>ZZT is boy</h1>
<img src="a.jpg"/>
</body>
</html>
[root@localhost html]#systemctl restart nginx.service 

在这里插入图片描述

2、网页准备

Web源主机配置:192.168.10.130(www.zztshiboy.com)

1.将a.jpg b.png文件传到/usr/local/nginx/html目录下,注意:编译安装html文件位置就在/usr/local/nginx/html,要是yum安装的话就在/usr/share/nginx/html
[root@localhost ~]# cd /apps/nginx/html/
[root@localhost html]# ls
50x.html  a.jpg  index.html
[root@localhost html]#2.配置首页文件
vim index.html
<html><body>
<h1>ZZT is boy</h1>
<img src="a.jpg"/></body>
</html>3.添加IP和域名的映射关系
[root@localhost html]#echo "192.168.10.130 www.zztshiboy.com" >> /etc/hosts
[root@localhost html]#echo "192.168.10.132 www.zzthenshuai.com" >> /etc/hosts

在这里插入图片描述
在这里插入图片描述
盗链网站主机配置:192.168.10.132(www.zzthenshuai.com)

1.切换到站点目录
[root@bogon ~]# cd /usr/share/nginx/html/2.配置首页文件,图片盗用Web源主机中的图片资源
vim index.html<html><body><title>test</title><img src="http://www.zztshiboy.com/a.jpg"/></body></html>3.添加IP和域名的映射关系
[root@bogon html]# echo "192.168.10.130 www.zztshiboy.com" >> /etc/hosts
[root@bogon html]# echo "192.168.10.132 www.zzthenshuai.com" >> /etc/hosts4.在盗图网站主机上进行浏览器查看
http://www.zztshiboy.com      #Web源主机
http://www.zzthenshuai.com    #盗链网站

在这里插入图片描述

3、Web源主机配置防盗链

当不是由web主机的域名请求图片资源时,统一将图片重写到b.png。

[root@localhost ~]#vim /usr/local/nginx/conf/nginx.conflocation ~* \.(jpg|gif|swf)$ {root html;expires 1d;valid_referers none blocked *.zztshiboy.com zztshiboy.com;if ( $invalid_referer ) {rewrite ^/ http://www.zztshiboy.com/b.png;}}
[root@localhost ~]#systemctl restart nginx##################注释#########################~* .(jpg|gif|swf)$ :这段正则表达式表示匹配不区分大小写,以.jpg 或.gif 或.swf 结尾的文件;valid_referers :设置信任的网站,可以正常使用图片;none:允许没有http_refer的请求访问资源(根据Referer的定义,它的作用是指示一个请求是从哪里链接过来的,如果直接在浏览器的地址栏中输入一个资源的URL地址,那么这种请求是不会包含 Referer 字段的),如 http://www.zzthenshuai.com/a.jpg。我们使用 http://www.zzthenshuai.com 访问显示的图片,可以理解成 http://www.zzthenshuai.com/a.jpg 这个请求是从 http://www.zzthenshuai.com 这个链接过来的。blocked:允许不是http://开头的,不带协议的请求访问资源; *.zzthenshuai.com:只允许来自指定域名的请求访问资源,如 http://www.zzthenshuai.comif语句:如果链接的来源域名不在valid_referers所列出的列表中,$invalid_referer为true,则执行后面的操作,即进行重写或返回 403 页面。

在这里插入图片描述
在这里插入图片描述

五、配置网页压缩

Nginx的ngx_http_gzip_module压缩模块提供对文件内容压缩的功能。

允许Nginx服务器将输出内容在发送客户端之前进行压缩,以节约网站带宽,提升用户的访问体验,默认已经安装。

可在配置文件中加入相应的压缩功能参数对压缩性能进行优化。

 #1、修改配置文件vim /usr/local/nginx/conf/nginx.confhttp {...... gzip on;                 #取消注释,开启gzip压缩功能gzip_min_length 1k;      #最小压缩文件大小gzip_buffers 4 64k;      #压缩缓冲区,大小为4个64k缓冲区gzip_http_version 1.1;   #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)gzip_comp_level 6;       #压缩比率gzip_vary on;            #支持前端缓存服务器存储压缩页面#压缩类型,表示哪些网页文档启用压缩功能gzip_types text/plain text/javascript application/x-javascript text/css text/xml application/xml application/xml+rss image/jpg image/jpeg image/png image/gif application/x-httpd-php application/javascript application/json;...... }#2、重启服务systemctl restart nginx#3、浏览器访问测试在Linux系统中,打开火狐浏览器,右击点查看元素选择 网络 ---> 选择 HTML、WS、其他 访问 http://www.zztshiboy.com ,双击响应消息查看响应头中包含 Content-Encoding: gzip

六、日志分割

随着Nginx运行时间的增加,产生的日志也会逐渐增加,为了方便掌握Nginx的运行状态,需要时刻关注Nginx日志文件。太大的日志文件对监控是一个大灾难,不便于分析排查,需要定期的进行日志文件的切割。

操作步骤

(1)、创建旧日志存放目录

(2)、通过mv命令将原有日志移动到日志目录中

(3)、kill -USR1 < PID> 重新生成日志文件

(4)、删除30天之前的日志文件

 1. #写脚本[root@localhost ~]# vim /opt/log.sh#!/bin/bash# Filename: log.sh# nginx日志分割,按时间分割#显示前一天的时间day=$(date -d "-1 day" "+%Y%m%d")#旧日志文件目录logs_path="/var/log/nginx"#nginx进程的PIDpid_path="/usr/local/nginx/logs/nginx.pid"#如果旧日志目录不存在,则创建日志文件目录[ -d $logs_path ] || mkdir -p $logs_path#将日志移动到旧日志目录,并重命名日志文件mv /usr/local/nginx/logs/access.log ${logs_path}/zztshiboy.com-access.log-$day#重建新日志文件kill -USR1 $(cat $pid_path) #删除30天之前的日志文件find $logs_path -mtime +30 -exec rm -rf {} ;           2. #赋予执行权限,执行脚本。查看日志文件目录。[root@localhost ~]# chmod +x /usr/local/nginx/nginx_log.sh [root@localhost ~]# /opt/log.sh[root@localhost ~]# ls /var/log/nginx/            //旧日志文件已被移动到设置好的目录zztshiboy.com-access.log-202200608[root@localhost ~]# ls /usr/local/nginx/logs/     //已重建新日志文件access.log  error.log  nginx.pid3. #编写计划任务,每天定点执行[root@localhost nginx]#crontab -e0 1 * * * /opt/fenge.sh

七、修改Nginx运行的用户和组

方法一:在编译安装时,指定运行用户和组(该方法仅在编译安装时使用)

 [root@localhost opt]# cd nginx-1.18.0/[root@localhost nginx-1.18.0]# ./configure \--prefix=/usr/local/nginx \       #指定nginx的安装路径--user=nginx \                    #指定用户名(运行用户)--group=nginx \                   #指定组名--with-http_stub_status_module    #启用http_stub_status_module模块以支持状态统计

方法二:修改配置文件nginx.conf

 #修改配置文件文件vim /usr/local/nginx/conf/nginx.confuser nginx nginx;       #取消注释,修改用户为nginx,组为nginx#重启服务systemctl restart nginx#查看是否修改成功。可以看到主进程由root创建,子进程由nginx创建ps aux | grep nginx

在这里插入图片描述
在这里插入图片描述

http://www.zhongyajixie.com/news/63128.html

相关文章:

  • 重视政府网站建设seo顾问张智伟
  • 贵州碧江区住房和城乡建设局网站百度前三推广
  • 网站网站开发的公司企业网络推广技巧
  • wordpress资讯站模板抖音指数查询
  • 北京营销型网站制作360营销
  • 给个龙做罗拉的网站电话号码宣传广告
  • 做网站蓝色和什么颜色搭配好看关于网站推广
  • 查网站服务器地址临沂seo优化
  • 制作 网站 盈利市场营销实务
  • 做网站建设需要什么工具现在什么网络推广好
  • 温州专业微网站制作网络公司网站接广告
  • 设迹官网百度seo关键词排名查询
  • 怎么用 c文件做网站百度网盘私人资源链接
  • 网络营销咨询网站源码网站交易平台
  • 政府网站建设申请报告体验式营销案例
  • wordpress 小程序投稿seo在线短视频发布页运营
  • 商城网站公司如何做好一个营销方案
  • 机械网站 英文湖南网站推广公司
  • 郑州市有做网站的吗营销推广型网站
  • wordpress网站制作新开网店自己如何推广
  • 网站页面设计师网站关键词优化有用吗
  • 如何做好网站建设谷歌关键词挖掘工具
  • dedecms做的系统网站主页是哪一个文件seo优化与品牌官网定制
  • 模仿采集网站生成网页没干过网络推广能干吗
  • 网站域名使用费多少抖音矩阵排名软件seo
  • 长春网站建设优化seo搜索引擎优化到底是什么
  • 学做网站多久能学会2023年免费b站推广大全
  • 营销型网站建设的关键特点百度站长工具怎么关闭
  • 哪里有手机网站建设济南网络营销外包
  • wordpress 简历 插件品牌seo主要做什么