书到用时方恨少,事非经过不知难。这篇文章主要讲述Web服务之Nginx优化与防盗链相关的知识,希望能为你提供帮助。
隐藏版本号
显示版本号
- 方法一:
- 方法二:
curl -I http://192.168.17.130

文章图片
隐藏版本号
- 方法一:修改配置文件方式
1.vim /usr/local/nginx/conf/nginx.conf http includemime.types; default_typeapplication/octet-stream; server_tokens off; #20行左右,添加,关闭版本号
3.curl -I http://192.168.17.130
+ 方法二:修改源码文件,重新编译安装
【Web服务之Nginx优化与防盗链】1.vim /opt/nginx-1.12.0/src/core/nginx.h
#define NGINX_VERSION " 1.1.1" #修改版本号
#define NGINX_VER " apache" NGINX_VERSION#修改服务器类型
2.cd /opt/nginx-1.12.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
3.make & & make install
4.vim /usr/local/nginx/conf/nginx.conf
http
includemime.types;
default_typeapplication/octet-stream;
server_tokens on;
......
5.systemctl restart nginx
6.curl -I http://192.168.17.130
******
# 修改用户与组
vim /usr/local/nginx/conf/nginx.conf
#取消注释,修改用户为nginx,组为 nginx
user nginx nginx;
systemctl restart nginx
#主进程由root创建,子进程由nginx创建
ps aux | grep nginx
****
# 缓存时间
+ 当nginx将网页数据返回给客户端后,可设置缓存的时间,以方便在日后进行相同内容的请求时直接返回,避免重复请求,加快了访问速度。
+ 一般针对静态王爷设置,对动态网页不设置缓存时间。
vim /usr/local/nginx/conf/nginx.conf
http
......
server
......
location /
root html;
index index.html index.htm;
location ~ \\.(gif|jpg|jepg|png|bmp|ico)$#加入新的 location,以图片作为缓存对象
root html;
expires 1d;
#指定缓存时间,1天
......
systemctl restart nginx.service
在Linux系统中,打开火狐浏览器,右击点查看元素
选择 网络 —>
选择 HTML、WS、其他
访问 http://192.168.17.130 ,双击200响应消息查看响应头中包含 Cahce-Control:max-age=86400 表示缓存时间是 86400 秒。也就是缓存一天的时间,一天之内浏览器访问这个页面,都是用缓存中的数据,而不需要向 Nginx 服务器重新发出请求,减少了服务器的使用带宽*****************# 日志切割
日志分割:
1.随着nginx运行时间增加,日志也会增加,为了方便掌握nginx运行状态,需要时刻关注nginx日志文件。
2.太大的日志文件对监控是一个大灾难
3.nginx自身不具备日志分割处理的功能,但可以通过nginx信号控制共功能的脚本实现日志的自动切割。
4.通过Linux的加护任务周期性进行日志切割。
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 运维工程师必备利器|一招实现运维智能化!
- 自动化集成(Pipeline整合Docker+K8S)
- centos7下配置tomcat环境变量
- 从内存管理原理,窥探OS内存管理机制
- jenkins批量修改配置文件
- 解决tomcat在Linux下启动缓慢问题
- Nginx优化与防盗链
- Linux(Ubuntu)搭建FastDFS文件管理系统
- netty系列之:JVM中的Reference count原来netty中也有