文章目录
一:Nginx优化与防盗链实验
前言
最近整理了一下Nginx的优化,详细介绍,更改用户与组、配置网页缓存、日志切割、设置连接超时等;
1.1:方法一:配置Nginx隐藏版本号
直接修改
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install gcc gcc-c++ pcre pcre-devel zlib-devel -y
解压缩
[root@localhost ~]# cd /opt
[root@localhost opt]# ls
rh
[root@localhost opt]# rz -E
rz waiting to receive.
[root@localhost opt]# tar zxvf nginx-1.12.2.tar.gz
创建管理用户
[root@localhost nginx-1.12.2]# useradd -M -s /sbin/nologin nginx
编译及安装
[root@localhost nginx-1.12.2]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
编译
[root@localhost nginx-1.12.2]# make
[root@localhost nginx-1.12.2]# make install
路径优化,便于系统管理
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
使用service控制
[root@localhost nginx-1.12.2]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
#增加权限
[root@localhost nginx-1.12.2]# chmod +x /etc/init.d/nginx
#重启服务
[root@localhost nginx-1.12.2]# service nginx start
#查看端口
[root@localhost nginx-1.12.2]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 22235/nginx: master
- 客户机访问
- 使用curl -l命令检测
-i参数可以显示 http response 的头信息,连同网页代码一起。-I 参数则只显示 http response 的头信息。
[root@server3 nginx-1.12.2]# curl -I http://192.168.158.30
HTTP/1.1 200 OK
Server: nginx/