发表于: 2018-02-11 23:08:09
2 743
今天完成的事情:
今天服务器被黑客攻击炸了,之前开的端口忘记关了,唉
幸好之前用history保存下来有历史命令行指令,重装起来也没有那么麻烦
今天就贴下有关服务器安全的知识吧,怎么禁止别人用ip直接访问你的服务器
因为朋友匀了我一个域名,我现在自己访问都是靠得域名访问:
打开文件/user/local/nginx/conf/nginx.conf
在server上面添加代码
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
#关闭访问日志
access_log off;
include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
#gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#配置代理参数
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_read_timeout 90;
proxy_send_timeout 90;
proxy_buffer_size 4k;
#缓存配置
proxy_temp_file_write_size 512k;
proxy_temp_path /mnt/nginx_temp;
proxy_cache_path /mnt/nginx_cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=400m;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#集群服务器
upstream tomcatserver {
#同一ip的访问不切换容器
ip_hash;
server 127.0.0.1:8081 max_fails=3 weight=1 fail_timeout=60s;
server 127.0.0.1:8082 max_fails=3 weight=1 fail_timeout=60s;
#server 127.0.0.1:8083 max_fails=3 weight=1 fail_timeout=60s;
}
server {
listen 80 default_server;
server_name _;
return 404;
}
server {
listen 80;
server_name 7.j2web.cn;
proxy_intercept_errors on;
# redirect server error pages to the static page /40x.html
error_page 404 /404.html;
location = /404.html {
}
error_page 403 = /403.html;
location = /403.html {
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /favicon.ico {
#关闭缩略图找不到时的警告
error_log off;
}
location ~ /\. {
#拒绝访问所有的.xxx隐藏文件
deny all;
error_log off;
}
location ~ .*\.(php|jsp)$ {
#拒绝访问
deny all;
error_log off;
}
location / {
#使用别名定位
proxy_pass http://tomcatserver/;
#数据存放目录
root html;
#默认首页文件,优先级从左到右
index index.html index.htm;
}
#静态资源请求全部到8088端口获取
location ~ .*\.(html|css|js|gif|jpg|jpeg|png|ttf|svg|eot|woff|woff2)$ {
proxy_cache cache_one;
proxy_cache_valid 200 304 302 1d;
proxy_cache_valid any 1d;
# 以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内
proxy_cache_key $host$uri$is_args$args;
add_header X-Cache '$upstream_cache_status from $host';
proxy_pass http://127.0.0.1:8088;
expires 1d;
}
}
#静态服务器
server{
listen 8088;
location ~ .*\.(html|css|js|gif|jpg|jpeg|png|ttf|svg|eot|woff|woff2)$ {
#所有静态文件直接读取硬盘
root /data/static;
#alias /data/static;
expires 1d;
}
}
}
代表的意思是所有除了已经配置的server_name可以访问外,其他地址返回444并断开连接
可以发现ip地址无法直接访问。
nginx禁止使用ip地址直接访问完成。
明天计划的事情:明天开始请假回老家了,十四天,已经和老大打过招呼了,手续也完全OK
遇到的问题:黑客
收获:理解到了服务器的安全性问题。
评论