從零開始在ubuntu上搭建node開發環境

建立用戶

(1) adduser username
(2) 受權 gpasswd -a txwg sudonode

配置 sudo visudo

(找到root ALL=(ALL:ALL) ALL 在下面添加 username ALL=(ALL:ALL) ALL)nginx

加強服務器安全級別

1.sudo vi /etc/ssh/sshd_configgit

  • 修改端口 port

2.修改防火牆權限github

  • 更新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)ubuntu

#!/bin/sh
iptable-restore /etc/iptable.up.rules

(sudo chmod +x /etc/network/if-up.d/iptables)vim

  1. 安裝fail2ban(主要監視你的系統日誌,而後匹配日誌的錯誤信息(正則式匹配)執行相應的屏蔽動做。)安全

    • 安裝 sudo apt-get install fail2ban
    • 配置信息 (sudo vi /etc/fail2ban/jail.conf)
    action = %(action_mw)s

### 配置node環境bash

  1. 安裝包服務器

    • 安裝 (sudo sudo apt-get install vim openssl build-essential libssl-dev wget curl git)
  2. 安裝nvmssh

nginx 反向代理

  1. 安裝

    • sudo apt-get install nginx
  2. 配置

    • sudo vi /etc/nginx/conf.d/name-com-port
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;
  }
}
  • 驗證nginx 配置信息 (sudo nginx -t)
  • 重啓nginx (sudo nginx -s reload)
相關文章
相關標籤/搜索