Nginx优化与防盗链

目录

一、nginx优化

1、配置Nginx影藏版本号

(1)修改配置文件

​编辑 (2)修改源码文件,重新编译安装

2、配置Nginx网页缓存时间

3、实现Nginx的日志分割

4、配置Nginx实现链接超时

5、更改Nginx运行进程数

6、配置网页压缩

二、防盗链


一、nginx优化

1、配置Nginx影藏版本号

隐藏Nginx版本号,避免安全漏洞泄漏

Nginx隐藏版本号的方法

       (1)修改配置文件
       (2)修改源码

(1)修改配置文件

将nginx配置文件中server_tokens选项的值设置为off

vim /usr/local/nginx/conf/nginx.conf
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;                                #添加,关闭版本号
    ......
}
 
systemctl restart nginx
curl -I http://192.168.10.103
 
 


 (2)修改源码文件,重新编译安装

vim /opt/nginx-1.12.0/src/core/nginx.h
#define NGINX_VERSION "1.1.1"                     #修改版本号
#define NGINX_VER "IIS" NGINX_VERSION             #修改服务器类型
 
cd /opt/nginx-1.12.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
make && make install
 
vim /usr/local/nginx/conf/nginx.conf
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens on;
    ......
}
 
systemctl restart nginx
curl -I http://192.168.10.103
 

nginx源码

2、配置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;				
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值