Tell me how to add a .net core 1.0 WebApp application to ubuntu in production?
- docs.asp.net/en/latest/publishing/linuxproduction.html - kmv am
- @kmv I didn’t understand how to work through a kestrel socket? My principle is not being created by me, or I am not looking there. And besides, when you restart the OS, the application does not rise - Sergey Fedorov
- their documentation is not updated github.com/aspnet/Docs/issues/1275 - kmv
1 answer
In general, this link is all detailed in detail (docs.asp.net/en/latest/publishing/linuxproduction.html). My steps were as follows (Ubuntu 04/16):
- Install .net core if not installed;
- Upload application binaries to the prod server, check that everything starts. Because If the server is deployed to Ubuntu, then you need to use Kestrel:
var host = new WebHostBuilder() .UseKestrel() .UseConfiguration(config) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup.Startup>() .Build(); - The article above recommends using nginx. While asp.net is not very friendly with ssl and other things, and nginx can. Therefore, we put it. In addition, you can configure normal routing: 1. Install: sudo apt-get install nginx 2. Start: sudo service nginx start 3. Check: sudo service nginx status
- In nginx.config (/etc/nginx/nginx.config) we configure the routing:
location / test / gateway / {
rewrite /test/gateway/(.*) /$1 break; 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; proxy_pass http://127.0.0.1:9595; } In proxy_pass, you specify the path to your application. I'm still on the same machine and deploy a test application, and production. Therefore, I use different URLs to access them.
rewrite /test/gateway/(.*) /$1 break; This command changes the url, removing / test / gateway /. Thus, access to the test and combat server differs only in the external url, there is no need to make changes inside the application.
- Let's make it so that the application loads at startup and reboots when it crashes. For this we use systemctl. In / etc / systemd / system create the file app_name.service with the following contents:
[Unit] Description=Gateway server for StreetFlow. [Service] TimeoutStartSec=0 ExecStart=/usr/bin/dotnet /etc/bt/st.gateway/GatewayServer.dll WorkingDirectory=/etc/bt/st.gateway Restart=always [Install] WantedBy=multi-user.target We indicate which command to execute, whether to run on error. You can also specify dependencies on, say, postgresql or nginx. After creating the service, you need to run two commands: sudo systemctl enable your_app sudo systemctl start your_app Sometimes after changing the config, the service may not start. This is treated with the sudo systemctl daemon-reload command.
Congratulations, your application is maximized!