创建用户
(1) adduser username
(2) 授权 gpasswd -a txwg sudo
配置 sudo visudo
(找到root ALL=(ALL:ALL) ALL 在下面添加 username ALL=(ALL:ALL) ALL)
增强服务器安全级别
1.sudo vi /etc/ssh/sshd_config
- 修改端口 port
2.修改防火墙权限
- 更新ubuntu sudo apt-get update && apt-get upgrade
- 更新完之后清空防火墙规则 iptable -F
- 写防火墙规则文件
*filter # allow all connenctions -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #allow out traffic -A INPUT -j ACCEPT #allow http https -A INPUT -p tcp --dport 443 -j ACCEPT -A INPUT -p tcp --dport 4200 -j ACCEPT -A INPUT -p tcp --dport 8081 -j ACCEPT # allow ssh port login -A INPUT -p tcp -m state --state NEW --dport 6666 -j ACCEPT #ping -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT # log denied calls -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied:" --log-level 7 #reject all other -A INPUT -j REJECT -A INPUT -j REJECT COMMIT
- 调用防火墙规则(sudo iptables-restore < /etc/iptables.ip.rules)
- 查看防火墙是否激活(sudo ufw status)
- 激活防火墙(sudo ufw enable)
- 设置开机自动启动防火墙规则
(sudo vi /etc/network/if-up.d/iptables)
#!/bin/sh iptable-restore /etc/iptable.up.rules
(sudo chmod +x /etc/network/if-up.d/iptables)
-
安装fail2ban(主要监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作。)
- 安装 sudo apt-get install fail2ban
- 配置信息 (sudo vi /etc/fail2ban/jail.conf)
action = %(action_mw)s
### 配置node环境
-
安装包
- 安装 (sudo sudo apt-get install vim openssl build-essential libssl-dev wget curl git)
-
安装nvm
- wget -qO- https://raw.githubusercontent... | bash (注:安装之后如果不可以用,根据提示配置一下环境变量)
- nvm node v9.0.0
Nginx 反向代理
upstream txwg { server 127.0.0.1:8081; } server { listen 80; server_name x.x.x.x; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Nginx-Proxy true; proxy_pass http://txwg; proxy_redirect off; } }