[root@server5 ~]# tar zxf nginx-1.10.1.tar.gz
[root@server5 core]# vim nginx.h
[root@server5 nginx-1.10.1]# vim auto/cc/gcc
[root@server5 nginx-1.10.1]# yum install -y gcc-c++
[root@server5 nginx-1.10.1]# yum install -y pcre-devel
[root@server5 nginx-1.10.1]# yum install -y openssl-devel
[root@server5 nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
[root@server5 nginx-1.10.1]# make && make install
1、绝对路径下载图片
[root@server5 sbin]# ln -s /usr/local/nginx/sbin/nginx /sbin/
[root@server5 sbin]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server5 sbin]# nginx
[root@server5 sbin]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 sbin]# nginx -s reload
[root@server5 sbin]# cd ..
[root@server5 nginx]# cd html/
[root@server5 html]# ls
50x.html index.html
[root@server5 html]# mkdir download
[root@server5 html]# cd download/
[root@server5 download]# ls
vim.jpg
[root@server5 download]# ll
total 444
-rwxr-xr-x 1 root root 453575 Aug 8 22:37 vim.jpg
在网页上输入绝对路径:172.25.50.5/download/vim.jpg
2、压力测试
a)由于线程设置是一所以均可以过去
[root@foundation50 Desktop]# ab -c1 -n 10 http://172.25.50.5/download/vim.jpg
[root@server5 nginx]# cd logs/
[root@server5 logs]# cat access.log
b)用十个线程进行测试
[root@foundation50 Desktop]# ab -c10 -n 10 http://172.25.50.5/download/vim.jpg
查看日志十个线程只可以过去一个其他的均报错503
3、设置带宽
[root@server5 logs]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 logs]# nginx -s reload
真机测试加入了带宽下载时间会相应的变化图片大小440k:
[root@foundation50 Desktop]# time wget http://172.25.50.5/download/vim.jpg
4、加入访问控制:
[root@server5 logs]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 logs]# nginx -s reload
[root@server5 logs]# cd ..
[root@server5 nginx]# cd html/
[root@server5 html]# mkdir admin
[root@server5 html]# cd admin/
[root@server5 admin]# vim index.html
写入:
admin page !!!
只有这个IP可以访问:
加入访问控制同一个网段可以访问
[root@server5 admin]# vim /usr/local/nginx/conf/nginx.conf
location /admin/ {
allow 172.25.50.0/24;
deny all;
}
[root@server5 admin]# nginx -s reload
5、静态文件的时间
[root@server5 admin]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 admin]# nginx -s reload
[root@server5 admin]# cd ..
[root@server5 html]# cd download/
[root@server5 download]# ls
vim.jpg
[root@server5 download]# cp vim.jpg ..
[root@server5 download]# cd ..
[root@server5 html]# ls
50x.html admin download index.html vim.jpg
[root@server5 html]#
在真机测试与设置的30天相符合:
[root@foundation50 Desktop]# curl -I http://172.25.50.5/vim.jpg
6、使访问本机时直接报错500
[root@server5 html]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 html]# nginx -s reload
网页访问,报错500
7、重定向:
[root@server5 html]# mkdir /www1
[root@server5 html]# cd /www1
[root@server5 www1]# vim index.html
[root@server5 www1]# cd /www1
[root@server5 www1]# ls
index.html ##写入 www.westos.org
[root@server5 www1]# mkdir bbs
[root@server5 www1]# cd bbs
[root@server5 bbs]# vim index.html ##c写入 www.westos.org - bbs
[root@server5 html]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 html]# nginx -s reload
访问bbs.westos.org会重定向:
8、中文乱码问题:
[root@server5 bbs]# cd ..
[root@server5 www1]# cat index.html
www.westos.org 你好
在网页测试会乱码:
修改配置文件:
[root@server5 www1]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 www1]# nginx -s reload
在网页输入www.westos.html/index.html
9、复制日志,将访问图片等日志关闭
[root@server5 www1]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 www1]# nginx -s reload
[root@server5 www1]# cd /usr/local/nginx/
[root@server5 nginx]# cd logs/
[root@server5 logs]# ll
total 36
-rw-r--r-- 1 root root 18175 Aug 9 02:34 access.log
-rw-r--r-- 1 root root 5408 Aug 9 02:36 error.log
-rw-r--r-- 1 root root 5 Aug 8 22:31 nginx.pid
[root@server5 logs]# du -h access.log
24K access.log
[root@server5 logs]# date
Thu Aug 9 02:37:12 EDT 2018
[root@server5 logs]# date +%F -d -1day
2018-08-08
[root@server5 logs]# cd /opt/
[root@server5 opt]# ls
[root@server5 opt]# vim nginx_log.sh
[root@server5 opt]# vim nginx_log.sh ##编写脚本每晚十二点移动日志重载服务
[root@server5 opt]# cat nginx_log.sh
#!/bin/bash
cd /usr/local/nginx/logs && mv access.log access.log_$(date +%F -d -1day)
/usr/local/nginx/sbin/nginx -s reload
[root@server5 opt]# crontab -e
[root@server5 opt]# chmod +x /opt/nginx_log.sh
[root@server5 opt]# /opt/nginx_log.sh
[root@server5 opt]# cd /usr/local/nginx/logs/
[root@server5 logs]# ls
access.log access.log_2018-08-08 error.log nginx.pid
[root@server5 logs]# ll
total 36
-rw-r--r-- 1 root root 0 Aug 9 02:40 access.log
-rw-r--r-- 1 root root 18175 Aug 9 02:34 access.log_2018-08-08
-rw-r--r-- 1 root root 5471 Aug 9 02:40 error.log
-rw-r--r-- 1 root root 5 Aug 8 22:31 nginx.pid
安装 阿帕奇
[root@server6 html]# ls
[root@server6 html]# vim index.html
[root@server6 html]# cat index.html ##写入一个默认访问
www.westos.org
在网页测试可以看到默认访问页记得打开阿帕奇
在nginx端默认访问放入照片:
[root@server5 html]# ls
50x.html admin download index.html vim.jpg
[root@server5 html]# cd /www1
[root@server5 www1]# ls
bbs index.html vim.jpg
什么是盗链?
盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有
利益的最终用户界面(如广告),直接在自己的网站上向最终用户提供
其它服务提供商的服务内容,骗取最终用户的浏览和点击率。受益者不
提供资源或提供很少的资源,而真正的服务提供商却得不到任何的收益。
在server6作盗链
[root@server6 html]# vim index.html
[root@server6 html]# cat index.html
<html>
<body>
<img src="http://www.westos.org/vim.jpg">
</body>
</html>
[root@server6 html]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.0.6 for ServerName
[ OK ]
直接调用server6的ip就可以看到server5的内容
在server5查看日志的时候,显示数据是从server6获取的,但显然不是,这样server6就可以一直给server5的服务器增加负载用来或取数据这就是盗链的意思
[root@server5 ~]# cd /usr/local/nginx/logs/
[root@server5 logs]# cat access.log
172.25.50.250 - - [09/Aug/2018:02:53:44 -0400] "GET /vim.jpg HTTP/1.1" 200 453575 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
172.25.50.250 - - [09/Aug/2018:03:18:04 -0400] "GET /vim.jpg HTTP/1.1" 200 453575 "http://172.25.50.6/" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
在server5配置防止盗链
[root@server5 logs]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 logs]# nginx -s reload
在网页访问:
给盗链用户回应一张图片
[root@server5 nginx]# mkdir /www2
[root@server5 nginx]# cd /www2
[root@server5 www2]# ls
[root@server5 www2]# ls
daolian.jpg
[root@server5 www2]# vim /usr/local/nginx/conf/nginx.conf
[root@server5 www2]# nginx -s reload
在网页测试其他主机访问的时候会回应一张照片