Fork me on GitHub

Linux 部署 ASP.NET Core 的一些问题记录

异常错误:

image

关闭 IP6

#修改
vi /etc/sysctl.conf
# 添加如下三条设置
   net.ipv6.conf.all.disable_ipv6 = 1
   net.ipv6.conf.default.disable_ipv6 = 1
   net.ipv6.conf.lo.disable_ipv6 = 1
# 执行
  sudo sysctl -p
# 查看状态( 显示应该是1)
cat /proc/sys/net/ipv6/conf/all/disable_ipv6

貌似没有啥用,后面只能通配符 *:5000 端口就好了(默认监听本地 localhost:5000 ,但是不建议这么做,最好是监听本地,外层 nginx 代理下配置灵活些)

复制代码
var host = new WebHostBuilder()
           .UseKestrel()
           .UseContentRoot(Directory.GetCurrentDirectory())
           .UseIISIntegration()
           .UseStartup<Startup>()
           .UseUrls("http://*:5000")
           .Build();
复制代码

查看占用某端口的程序
#查看已经连接的服务端口(ESTABLISHED)
netstat -a
#查看所有的服务端口(LISTEN,ESTABLISHED)
netstat -ap
#查看8080端口,则可以结合grep命令:
netstat -ap | grep 8080
#查看8888端口
lsof -i:8888
#停止使用这个端口的程序
kill +对应的pid即可

# MAC 配置 dotnet 环境
brew update
brew install openssl
mkdir -p /usr/local/lib
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
install .NET Core 1.1

#工具的选择
Visual Studio Code
JetBrains Rider

#启动爬虫
curl http://localhost:6800/schedule.json -d project=stockhq -d spider=stock_hq_jrj_spider

#nginx
sudo apt-get install nginx
sudo service nginx start
sudo service nginx restart

vi /etc/nginx/nginx.conf

复制代码
server {
listen 80;
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;
}
}
复制代码

#supervisor

sudo apt-get install supervisor
cd /etc/supervisor/conf.d/
touch stockhq.conf

[program:stockhq]
command=dotnet stockhq-web.dll
directory=/opt/stockhq-web/
autostart=true
autorestart=true
stderr_logfile=/var/log/stockhq.err.log
stdout_logfile=/var/log/stockhq.out.log

#重启服务

sudo service supervisor stop
sudo service supervisor start

#查看日志
sudo tail -f /var/log/supervisor/supervisord.log
tail -f /var/log/stockhq.out.log

#Cope 文件
dotnet publish
scp -r //Users/Irving/Desktop/python/irving/stockhq-web/bin/Debug/netcoreapp1.1/publish/ root@120.26.40.126:/opt/stockhq-web/

REFER:
https://docs.microsoft.com/zh-cn/aspnet/core/publishing/linuxproduction
https://github.com/aspnet/Docs/blob/e9c1419175c4dd7e152df3746ba1df5935aaafd5/aspnetcore/publishing/linuxproduction.md
https://www.microsoft.com/net/core#linuxubuntu
https://www.microsoft.com/net/core#macos
http://www.cnblogs.com/cmt/p/5504731.html

posted @   花儿笑弯了腰  阅读(553)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示