第一课:.net core 入门
1. Visual Studio 可以直接创建一个project
2. 可以使用命令行创建,例如
dotnet new webapi -o apidemo1
然后用Visual studio code编辑。一般的文档编辑器也可以,但是vsc有很多插件会比较方便
Computer has revolutionized the world and programming is the most important tool to make our dream come true;
第一课:.net core 入门
1. Visual Studio 可以直接创建一个project
2. 可以使用命令行创建,例如
dotnet new webapi -o apidemo1
然后用Visual studio code编辑。一般的文档编辑器也可以,但是vsc有很多插件会比较方便
sudo apt-get install ssmtp
sudo apt-get install mailutils
sudo nano /etc/ssmtp/ssmtp.conf
root=postmaster
mailhub=smtp.gmail.com:587
hostname=raspberrypi
AuthUser=AGmailUserName@gmail.com
AuthPass=TheGmailPassword
FromLineOverride=YES
UseSTARTTLS=YES
echo "Hello world email body" | mail -s "Test Subject" recipientname@domain.com
$ sudo apt-get install software-properties-common $ sudo add-apt-repository ppa:certbot/certbot $ sudo apt-get update $ sudo apt-get install certbot
certbot certonly --webroot -w /var/www/example -d example .com -d www.example .com
注意:此时需要修改default站点 /etc/nginx/sites-enabled/default ,修改root到/var/www/example
并且打开autoindex on;
而且需要在nginx.conf下取消其他服务器
打开自建host站点的配置文件修改如下:
server {
listen 80;
index index.html index.htm;
server_name example .com; #域名
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 80;
index index.html index.htm;
server_name www.example .com; #域名
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example .com;
ssl_certificate /etc/letsencrypt/live/example .com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example .com/privkey.pem;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_ciphers '×××××××××××××××××××';
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
location / {
proxy_pass http://localhost:5000; # 自动代理
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
注意:let's encrypt 每三个月需要更新一次ssl证书,执行下列命令 certbot renew --dry-run
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893sudo apt-get updatesudo apt-get install dotnet-dev-1.0.1
server {
listen 80;index index.html index.htm;server_name www.osscoder.com; #域名location / {
proxy_pass http://127.0.0.1:8000; # 刚才设置的地址端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
[program:OSS.Offical.Site]
command=dotnet OSS.Offical.Site.dll //要执行的命令
directory=/home/www/ossoffical //命令执行的目录
environment=ASPNETCORE__ENVIRONMENT=Production #环境变量
user=osscoder //进程执行的用户身份
stopsignal=INT
autostart=true
autorestart=true
startsecs=3 //自动重启间隔
stderr_logfile=/var/log/ossoffical.err.log //标准错误日志
stdout_logfile=/var/log/ossoffical.out.log //标准输出日志
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list' sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893 sudo apt-get update
sudo apt-get install dotnet-dev-1.0.0-preview2-003131
dotnet --version
mkdir NetWeb cd NetWeb dotnet new
dotnet restore
dotnet run
dotnet ***.dll
# 列出规则,供查看
iptables -L -n
# stop iptables, 如果清空规则前没有停止,ssh 会断掉,必须重启系统
/etc/init.d/iptables stop
# 清空规则
iptables -F
# 允许内网ip访问所有端口
iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT
# 允许本地回环接口(即运行本机访问本机)
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
# 允许访问22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 允许访问80端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# 允许所有ip访问80端口
iptables -A INPUT -p tcp -s 0/0 --dport 80 -j ACCEPT
# 允许本地发起的连接返回数据到任意端口。本地作为客户端可以发起到任何ip和端口的请求,这条规则确保能够收到返回
#------------------when conntrack unkonw error use this
# sudo /sbin/iptables -A OUTPUT -m state --state NEW,ESTABLISHED -j ACCEPT
# sudo /sbin/iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
# sudo /sbin/iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
#---------------------------------------------------------------
iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
# 允许80端口返回数据
iptables -A OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT
# 允许返回数据给所有ip所有端口 允许所有本机向外的访问
iptables -A OUTPUT -j ACCEPT
# 除上面允许的规则,抛弃所有INPUT请求 (注意:如果22端口未加入允许规则,SSH链接会直接断开。)
iptables -P INPUT DROP
# 除上面允许的规则,抛弃所有FORWARD请求
iptables -P FORWARD DROP
# 除上面允许的规则,抛弃所有OUTPUT请求
iptables -P OUTPUT DROP
# 备份
iptables-save > /etc/iptables/iptables.rules
# (cat /etc/sysconfig/iptables > /etc/iptables/iptables.rules )
# 保存(ArchLinux系统下的路径可能和其他系统下的路径不同)
sudo /etc/rc.d/init.d/iptables save
# 重新启动
sudo service iptables restart
# (/etc/init.d/iptables restart)
# 列出规则,供查看
iptables -L -n
# iptables 安装后 iptables 命令无效,可能是因为该用户的PATH不包括/sbin和/usr/sbin, 可用 sudo /sbin/iptables 运行