公司给了个阿里云服务器,自己搭了测试环境。没过几天,发现被扫描了,内容大概这样
2019/10/29 20:53:59 [error] 1269#0: *5878 open() "xxxxx/whoami.php" failed (2: No such file or directory), client: 172.105.23.36, server: localhost, request: "GET /whoami.php HTTP/1.1", host: "xxx.xxx.xxx.xxx"
2019/10/29 20:57:39 [error] 1269#0: *5879 open() "xxxxx/cache/global/img/gs.gif" failed (2: No such file or directory), client: 80.82.70.187, server: localhost, request: "GET http://www.baidu.com/cache/global/img/gs.gif HTTP/1.1", host: "www.baidu.com"
2019/10/29 21:01:01 [error] 1269#0: *5882 open() "xxxxx/cache/global/img/gs.gif" failed (2: No such file or directory), client: 80.82.70.187, server: localhost, request: "GET http://www.baidu.com/cache/global/img/gs.gif HTTP/1.1", host: "www.baidu.com"
2019/10/29 22:45:18 [error] 1269#0: *5923 open() "xxxxx/editBlackAndWhiteList" failed (2: No such file or directory), client: 159.203.196.79, server: localhost, request: "GET /editBlackAndWhiteList HTTP/1.1", host: "xxx.xxx.xxx.xxx", referrer: "188.65.219.106"
2019/10/29 23:48:55 [error] 1269#0: *5936 open() "xxxxx/index.php" failed (2: No such file or directory), client: 45.67.14.148, server: localhost, request: "POST /index.php HTTP/1.1", host: "xxx.xxx.xxx.xxx"
2019/10/30 03:23:02 [error] 1269#0: *5963 open() "xxxxx/azenv.php" failed (2: No such file or directory), client: 95.213.177.124, server: localhost, request: "POST http://check.proxyradar.com/azenv.php?auth=157237698109&a=PSCN&i=2018398604&p=80 HTTP/1.1", host: "check.proxyradar.com", referrer: "http://best-proxies.r(这里博客园提示敏感词,汗。。)u/"
嗯。。我一个java后台你扫我php。。
还有为什么会有来自百度的请求,麻烦知道的大佬指教一二,先谢过了!
好可怕,吓得我赶紧改了远程端口,记录一下。
修改远程端口
1 先决定一个新的远程端口(这里用12345举例),去服务器的安全组开放此端口。
2 远程连接进服务器
vim /etc/ssh/sshd_config
先将Port 22前面的注释放开,然后再其下面再添加一条(这样22和12345都可远程连接。这么做是为了一会先试新端口,成功了再回来关闭22端口,不然直接改了回头发现新端口连不上就坑大了)
Port 22
Port 12345
3 重启sshd
service sshd restart
4 用新端口远程连接,成功后关闭安全组的22端口(到这里发现sshd_config的22端口开着好像也没事,因为最外面的安全组已经屏蔽了)。
关闭8080端口
改好远程端口后,突然又想到,项目是前后台分离,前端80,后端8080。但其实对外只用暴露80端口,8080不需要暴露,这不是又多了一个别人扫你api的风险么。
于是,利用nginx的转发功能实现之。
1 将后台的api访问url由xxx.xxx.xxx.xxx:8080改为xxx.xxx.xxx.xxx/api
2 nginx的配置添加
location /api/ {
proxy_pass http://localhost:8080/;
}
这里说下proxy_pass 后面的url带斜线(/)和不带的区别
假设后台访问路径为test.do
1) 加斜线就是直接将配置的路径转发到url下,例如
```
location /api/ {
proxy_pass http://localhost:8080/;
}
```
最后访问路径为 http://localhost:8080/test.do
2) 不加斜线是将配置的路径加入到url后面,例如
```
location /api/ {
proxy_pass http://localhost:8080;
}
```
最后访问路径为 http://localhost:8080/api/test.do
那么我这里当然是使用加斜线的配置
再顺带一提,如果后台做了负载均衡,只用把proxy_pass后面换成对应的upstream即可,如
location /api/ {
proxy_pass http://backend/;
}
upstream backend {
server localhost:8081 weight=1;
server localhost:8082 weight=1;
}
嗯,好像彻底没8080端口什么事了。
3 重启nginx
./nginx -s reload
总结
OK,到这里整个服务器对外只暴露80端口(远程端口对外界是未知的)。
至于数据库,redis(记得设置密码)等远程端口,在测试阶段可以开放,最后生产环境还是关闭比较安全。