一. 安装Nginx服务,作为主服务器
//解压缩包
tar zxvf nginx-1.12.2.tar.gz -C /opt
//创建用户
useradd -M -s /sbin/nologin nginx
//安装环境依赖包
yum install gcc gcc-c++ pcre pcre-devel zlib-devel -y
//配置
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
//创建软连接,便于管理服务命令
ln -s /usr/local/nginx/sbin/* /usr/local/sbin
//便于service管理服务
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);;
*)
exit 1
esac
exit 0
//添加执行权限
chmod +x /etc/init.d/nginx
//添加为系统服务
chkconfig --add nginx
//启动服务
service nginx start
//验证服务
netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 43330/nginx: master
访问服务网站
二 .安装盗链网站服务
yum install httpd -y //安装apache服务
systemctl start httpd //开启服务
systemctl stop firewalld.service //关闭防火墙
vim /var/www/html/index.html
<html>
this is httpd web
<body>
<img src="http://192.168.179.185/lol.jpg"/> //盗用nginx服务网站图片
</body>
</html>
三 .更改nginx服务的主配置文件,开启防盗链功能
//在配置文件中的server段添加
location ~*\.(jpg|gif|swf)$ {
valid_referers none blocked *.yun.com yun.com;
if ( $invalid_referer ) {
rewrite ^/ http://www.yun.com/error.png;
}
}
//重启nginx服务
service nginx stop
service nginx start
验证