搭建基本的网站页面

coding

  1. cd /opt/tengine233/html
  2. mkdir a
  3. mkdir b
  4. mkdir c
  5. echo aaa >a/index.html
  6. echo bbb >b/index.html
  7. echo cccc >c/index.html
  8. elinks http://127.0.0.1 --dump

effect

主页面图片.png

子页面图片.png

访问控制

Solution1 —- white list of IP

code

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. charset utf-8;
  5. #access_log logs/host.access.log main;
  6. #access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
  7. location / {
  8. root html;
  9. index index.html index.htm;
  10. }
  11. # /opt/tengine233/html/a/html
  12. location /a {
  13. #allow 127.0.0.1;
  14. deny all;
  15. }

effect

图片.png

redirect 404

code

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. charset utf-8;
  5. #access_log logs/host.access.log main;
  6. #access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
  7. location / {
  8. root html;
  9. index index.html index.htm;
  10. }
  11. # /opt/tengine233/html/a/html
  12. location /a {
  13. allow 127.0.0.1;
  14. deny all;
  15. return 404;
  16. }
  17. error_page 404 /404.html;

effect图片.png

redirect website

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. charset utf-8;
  5. #access_log logs/host.access.log main;
  6. #access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
  7. location / {
  8. root html;
  9. index index.html index.htm;
  10. }
  11. # /opt/tengine233/html/a/html
  12. location /a {
  13. allow 127.0.0.1;
  14. deny all;
  15. return https://image.baidu.com/;
  16. }
  17. error_page 404 /404.html;

effect

图片.png图片.png图片.png

visit by passwd

ready

  1. 1. 处理包依赖
  2. yum -y install httpd-devel-2.4.6-97.el7.centos.1.x86_64
  3. yum -y install httpd-tools
  4. 2. 使用htpasswd生成密码,不存在参数为c 存在则参数为m
  5. touch /opt/nginx/htpasswd
  6. htpasswd -c /opt/nginx/htpasswd sky
  7. 3. nginx 配置文件
  8. location /b {
  9. auth_basic "登陆验证";
  10. auth_basic_user_file /etc/nginx/htpasswd;
  11. }

effect

图片.pngself-made log

configure

  1. http {
  2. include mime.types;
  3. default_type application/octet-stream;
  4. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  5. # '$status $body_bytes_sent "$http_referer" '
  6. # '"$http_user_agent" "$http_x_forwarded_for"';
  7. #access_log logs/access.log main;
  8. #access_log "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G" main;
  9. log_format caesar_01 '[$time_local] $remote_addr "$request" $status'
  10. server {
  11. access_log logs/host.access.log caesar_01;
  12. location /a{
  13. }
  14. }
  15. }

operation

  1. 1. 重载Nginx配置文件
  2. nginx -s reload
  3. 2. 访问日志文件,并且动态显示
  4. cd /opt/tengin233/log
  5. tailf host.acess.log
  6. 3. 浏览器访问页面

effect

图片.pnglog_format in json

introduction

  1. Nginx访问日志主要有两个参数控制
  2. 1. log_ format #用来定义记录日志的格式(可以定义多种日志格式,取不同名字即可)
  3. log. format log. name string
  4. 2. access_ log #用来指定日至文件的路径及使用的何种日志格式记录日志
  5. access_ log logs/access.log main;
  6. log. format格式变量:
  7. $remote_addr #记录访问网站的客户端地址
  8. $remote_user #远程客户端用户名
  9. $time_local #记录访问时尚与时区
  10. $request #用户的http请求起始行信息
  11. $status #tp状态码,记录请求返回的状态码,例如: 200、 301、 404等
  12. $body_bytes_sent #服务器发送给客户端的响应body字节数
  13. $http_referer #记录此次请求是从哪个连接访问过来的,可以根据该参 数进行防盗链设置。
  14. $http_user_agent #记录客户端访问信息,例如:浏览器、手机客户端等
  15. $http_x_forwarded for #当前端有代理服务器时,设置web节点记录客户端地址的配置,此参数生效的前是是代服务 器也要进行相关的x_forwarded for设置

cofiguratiion

  1. http {
  2. include mime.types;
  3. default_type application/octet-stream;
  4. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  5. # '$status $body_bytes_sent "$http_referer" '
  6. # '"$http_user_agent" "$http_x_forwarded_for"';
  7. #access_log logs/access.log main;
  8. #access_log "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G" main;
  9. #log_format caesar_01 '[$time_local] $remote_addr "$request" $status'
  10. log_format main_json '{"@timestamp":"$time_iso8601",'
  11. '"@version":"1",'
  12. '"server_addr":"$server_addr",'
  13. '"remote_addr":"$remote_addr",'
  14. '"host":"$host",'
  15. '"uri":"$uri",'
  16. '"body_bytes_sent":$body_bytes_sent,'
  17. '"bytes_sent":$body_bytes_sent,'
  18. '"upstream_response_time":$upstream_response_time,'
  19. '"request":"$request",'
  20. '"request_length":$request_length,'
  21. '"request_time":$request_time,'
  22. '"status":"$status",'
  23. '"http_referer":"$http_referer",'
  24. '"http_x_forwarded_for":"$http_x_forwarded_for",'
  25. '"http_user_agent":"$http_user_agent"'
  26. '}';
  27. sendfile on;
  28. #tcp_nopush on;
  29. #keepalive_timeout 0;
  30. keepalive_timeout 65;
  31. gzip on;
  32. server {
  33. listen 80;
  34. server_name localhost;
  35. charset utf-8;
  36. access_log logs/host.access.log main_json;
  37. }
  38. }

effect

图片.png

thef link from other

operation

  1. ### default website
  2. curl -e "https://www.baidu.com" -I https://www.whereabouts.cn/fly/blog/img/linhaifeng.jpg
  3. curl -e "https://www.google.com" -I https://www.whereabouts.cn/fly/blog/img/linhaifeng.jpg
  4. location /media {
  5. valid_referers none blocked server_names *.example.com example.* www.example.org/galleries/~\.google\.;
  6. if ($invalid_referer){
  7. return 404;
  8. }
  9. alias /opt/whereabouts/media/;
  10. }

configuration

  1. valid_referers none blocked *.ayitula.com;
  2. if ($invalid_referer){
  3. return 403;
  4. }

refer图片.png

图片.png

reference

  1. https://www.cnblogs.com/htfhtf/p/15174613.html
  2. https://blog.csdn.net/qq_33240556/article/details/121113328
  3. [official doc]
  4. https://nginx.org/en/docs/http/ngx_http_referer_module.html
  5. [Embedded Variables]
  6. https://www.jianshu.com/p/12b9c364b86a
  7. [Python home source]
  8. https://mirrors.huaweicloud.com/python/