[root@nginxserver server]#vim www_magedu_net.conf
root /data/nginx/html/pc;
if (!-f $request_filename) {
#return 404 "linux36";
rewrite (.*) http://www.magedu.net/index.html;
}
[root@nginxserver server]#nginx-r
这个是判断用户的请求是否存在,如果不存在就跳转到首页去
[root@nginxserver server]#vim www_mageedu_net.conf
server {
listen 80;
server_name www.mageedu.net;
access_log /apps/nginx/logs/www_mageedu_net_access.log access_json;
error_log /apps/nginx/logs/www_mageedu_net_error.log;
location / {
root /data/nginx/html/megeedu;
index index.html;
}
}
}
[root@nginxserver server]#mkdir /data/nginx/html/megeedu
[root@nginxserver server]#cd /data/nginx/html/megeedu
[root@nginxserver megeedu]#vim index.html 写入一个倒链页面
server {
listen 80;
server_name www.mageedu.net;
access_log /apps/nginx/logs/www_mageedu_net_access.log access_json;
error_log /apps/nginx/logs/www_mageedu_net_error.log;
location / {
root /data/nginx/html/megeedu;
index index.html;
}
}
访问刚创建的页面,上边的图片盗链的是magedu的网站,下边的图片盗链的是京东的网站
查看日志信息[root@nginxserver ~]#tail -f /apps/nginx/logs/www_magedu_net_*.log
查看哪个网站在盗链
[root@nginxserver server]#vim www_magedu_net.conf
ssl_session_timeout 10m;
location / {
root /data/nginx/html/pc;valid_referers none blocked server_names *.baidu.com *.example.com example.* www.example.org/galleries/ ~\.google\.; 定义禁止盗链的信息
[root@nginxserver server]#nginx-r
[root@client ~]#free -m 查看内存的信息
total used free shared buff/cache available
Mem: 3773 124 3485 11 162 3428
Swap: 3967 0 3967
[http://tengine.taobao.org/download.html](http://tengine.taobao.org/download.html)
访问teng.org网站
[root@nginxserver ~]#nginx -s stop 停止这个服务
[root@nginxserver src]#cd /usr/local/src/
[root@nginxserver src]#wget http://tengine.taobao.org/download/tengine-2.3.0.tar.gz
[root@nginxserver src]#tar xf tengine-2.3.0.tar.gz 解压
这个命令是检查环境的 ./configure
--prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/root/echo-nginx-module
复制nginx的编译参数
[root@nginxserver tengine-2.3.0]#./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/root/echo-nginx-module
开始编译tng
[root@nginxserver tengine-2.3.0]#make 安装
[root@nginxserver tengine-2.3.0]#make clean
rm -rf Makefile objs
[root@nginxserver tengine-2.3.0]#./configure --prefix=/usr/local/tengine --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/root/echo-nginx-module
重新编译安装,注意目录
[root@nginxserver tengine-2.3.0]#make
[root@nginxserver tengine-2.3.0]#make install 安装
[root@nginxserver conf]#vim /usr/local/tengine/conf/nginx.conf
include /apps/nginx/conf/server/*.conf; 引入之前的nginx的所有配置信息
[root@nginxserver conf]#/usr/local/tengine/sbin/nginx -V 查看tengine版本
Tengine version: Tengine/2.3.0 (nginx/1.15.9)
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/tengine --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/root/echo-nginx-module
[root@nginxserver home]#/usr/local/tengine/sbin/nginx -t
nginx: [emerg] unknown log format "access_json" in /apps/nginx/conf/server/www_magedu_net.conf:5 提示日志不支持
nginx: configuration file /usr/local/tengine/conf/nginx.conf test failed
[root@nginxserver home]#vim /usr/local/tengine/conf/nginx.conf
log_format access_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"uri":"$uri",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"tcp_xff":"$proxy_protocol_addr",'
'"http_user_agent":"$http_user_agent",'
'"status":"$status"}';
[root@nginxserver home]#/usr/local/tengine/sbin/nginx -t 在检查下没有问题
nginx: the configuration file /usr/local/tengine/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/tengine/conf/nginx.conf test is successful
[root@nginxserver home]#/usr/local/tengine/sbin/nginx 启动服务
[root@nginxserver home]#echo "alias tnginx='/usr/local/tengine/sbin/nginx'" >>/etc/profile 修改变量
[root@nginxserver home]#source /etc/profile 执行脚本
[root@nginxserver home]#tnginx 开启服务
[root@nginxserver conf]#vim /usr/local/tengine/conf/nginx.conf
server_tokens off;
[root@nginxserver conf]#tnginx -s reload
[root@nginxserver /]#cd /apps/nginx/conf/server/
[root@nginxserver server]#vim www_magedu_net.conf
location ^~ /static {
root /data/nginx/html/pc;
concat on;
index index.html;
}
[root@nginxserver tengine-2.3.0]#./configure --help |grep concat 过滤这个值
tng早期的版本支持这个功能