nginx 基本命令
nginx 路径:
cd /etc/nginx
重启:
nginx -s reopen
或
nginx
重新载入配置:
nginx -s reload
关闭停止
nginx -s stop
nginx -s quit
nginx 禁止 ip 访问
将端口号80的监听设置为默认虚拟主机default
server {
listen 80 default;
server_name _;
rewrite ^(.*) http://www.*****.cn permanent;
}
nginx 禁用 ip
在服务器 nginx 目录中创建 denyip.conf, 并将此文件添加到 nginx.conf 文件中的 include 字段中
include denyip.conf
在 denyip.conf 中配置屏蔽的 ip
deny 123.23.0.0/16;
deny 134.112.0/24;
deny 111.112.113.14;
或者
deny all;
运行特定 ip 和上面一样,只需要将 deny
改成 allow
即可
禁止某个爬虫爬取(YisouSpider)
1、可以通过查询 nginx 的访问日志,找出 ip
进入 nginx 的 log 日志目录,然后执行如下命令,找出 爬虫的 ip
cat access.log | grep -i "YisouSpider" | awk '{print $1,";"}' > yisouspider_iplog.txt
然后将找出来的 ip 放到 denyip.conf 中进行禁止访问
这种方法通过禁用 ip 的方式其实是一种无奈之举,爬虫的 ip 有很多,只能被动的发现一个添加一个。
nginx 如下报错:
1、80端口被占用
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
说明端口 80 被占用
执行:
# root 用户
fuser -k 80/tcp
然后重启 nginx 即可
2、配置文件找不到
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
重新指定配置文件
nginx -t
#得到如下
nginx: the configuration file /***/***/nginx.conf syntax is ok
nginx: configuration file /***/**/nginx.conf test is successful
# 将路径 /***/***/nginx.conf 配置
nginx -c /***/***/nginx.conf
Nginx 防止恶意镜像
最近发现搜索自己的博客文章,竟然搜到其他域名一模一样的文章,点进去发现,好家伙完全就是我的博客小站嘛,所有文章包括个人标识都一模一样。随后ping 了一下这个域名,结果 ping 到了我自己的服务器 ip 上,说明我的服务器 ip 被人恶意解析了。赶紧采取措施


修改 nginx 的配置,指定域名,将不是自己域名的直接返回403
server {
listen 80;
listen [::]:80;
server_name 自己的域名;
set $deny 1;
if ($host = '自己的域名'){
set $deny 0;
}
if ($deny = 1) {
return 403;
}
root /***/***/**/***/blog;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
# Load configuration files for the default server block.
include /***/***/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
这种服务器 ip 招人恶意解析,可千万不能侥幸,发现了一定要及时处理,否则可能会影响自己服务器ip被封杀,毕竟你不知道恶意解析的域名到底是做什么用的,万一是无良的呢,而且本来就已经恶意解析了,对方肯定不是什么好鸟。
原文始发于微信公众号(三万之一):Nginx 操作相关
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/231143.html