{"id":64,"date":"2025-11-15T03:51:40","date_gmt":"2025-11-15T03:51:40","guid":{"rendered":"https:\/\/blogs.giamkichsan.com\/?p=64"},"modified":"2025-11-16T14:46:27","modified_gmt":"2025-11-16T14:46:27","slug":"build-va-chay-mot-ung-dung-web-net-core-net-6-7-8-tren-centos","status":"publish","type":"post","link":"https:\/\/blogs.giamkichsan.com\/index.php\/2025\/11\/15\/build-va-chay-mot-ung-dung-web-net-core-net-6-7-8-tren-centos\/","title":{"rendered":"Build v\u00e0 ch\u1ea1y m\u1ed9t \u1ee9ng d\u1ee5ng Web .NET Core (.NET 6\/7\/8) tr\u00ean CentOS"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>4\ufe0f\u20e3 Ch\u1ea1y \u1ee9ng d\u1ee5ng tr\u00ean CentOS<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Ch\u1ea1y tr\u1ef1c ti\u1ebfp<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet run\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>M\u1eb7c \u0111\u1ecbnh \u1ee9ng d\u1ee5ng s\u1ebd ch\u1ea1y tr\u00ean <strong><code>http:\/\/localhost:5000<\/code><\/strong> v\u00e0 <strong><code>https:\/\/localhost:5001<\/code><\/strong>.<\/li>\n\n\n\n<li>B\u1ea1n c\u00f3 th\u1ec3 m\u1edf firewall \u0111\u1ec3 truy c\u1eadp t\u1eeb b\u00ean ngo\u00e0i:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --add-port=5000\/tcp --permanent\nsudo firewall-cmd --reload\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Ch\u1ea1y \u1edf ch\u1ebf \u0111\u1ed9 production<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet publish -c Release -o \/var\/www\/mywebapp\ncd \/var\/www\/mywebapp\ndotnet MyWebApp.dll\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5\ufe0f\u20e3 C\u00e0i \u0111\u1eb7t d\u1ecbch v\u1ee5 systemd \u0111\u1ec3 ch\u1ea1y t\u1ef1 \u0111\u1ed9ng<\/strong><\/h2>\n\n\n\n<p>T\u1ea1o file d\u1ecbch v\u1ee5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/systemd\/system\/mywebapp.service\n<\/code><\/pre>\n\n\n\n<p>N\u1ed9i dung v\u00ed d\u1ee5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\nDescription=My .NET WebApp\n\n&#91;Service]\nWorkingDirectory=\/var\/www\/mywebapp\nExecStart=\/usr\/bin\/dotnet \/var\/www\/mywebapp\/MyWebApp.dll --urls \"http:\/\/0.0.0.0:5000\"\nRestart=always\nRestartSec=10\nSyslogIdentifier=dotnet-mywebapp\nUser=www-data\nEnvironment=ASPNETCORE_ENVIRONMENT=Production\n\n&#91;Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n\n\n\n<p>Sau \u0111\u00f3 k\u00edch ho\u1ea1t:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo systemctl enable mywebapp.service\nsudo systemctl start mywebapp.service\nsudo systemctl status mywebapp.service\n<\/code><\/pre>\n\n\n\n<p>\u1ee8ng d\u1ee5ng c\u1ee7a b\u1ea1n b\u00e2y gi\u1edd s\u1ebd ch\u1ea1y <strong>nh\u01b0 m\u1ed9t service<\/strong>, t\u1ef1 kh\u1edfi \u0111\u1ed9ng c\u00f9ng m\u00e1y ch\u1ee7.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reload v\u00e0 restart service n\u1ebfu c\u1ea7n:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo systemctl restart mywebapp.service\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 <strong>6. Xem log d\u1ecbch v\u1ee5 (r\u1ea5t quan tr\u1ecdng khi debug)<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo journalctl -fu mywebapp.service\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 <strong>7. C\u00e1c l\u1ec7nh qu\u1ea3n l\u00fd d\u1ecbch v\u1ee5 kh\u00e1c<\/strong><\/h3>\n\n\n\n<p>D\u1eebng d\u1ecbch v\u1ee5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl stop mywebapp.service\n<\/code><\/pre>\n\n\n\n<p>Kh\u1edfi \u0111\u1ed9ng l\u1ea1i:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart mywebapp.service\n<\/code><\/pre>\n\n\n\n<p>X\u00f3a t\u1ef1 ch\u1ea1y:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl disable mywebapp.service<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6\ufe0f\u20e3 (Tu\u1ef3 ch\u1ecdn) D\u00f9ng Nginx l\u00e0m reverse proxy<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\u00e0i Nginx:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install nginx -y\nsudo systemctl enable --now nginx\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\u1ea5u h\u00ecnh reverse proxy cho .NET:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 80;\n    server_name yourdomain.com;\n\n    location \/ {\n        proxy_pass         http:\/\/127.0.0.1:5000;\n        proxy_http_version 1.1;\n        proxy_set_header   Upgrade $http_upgrade;\n        proxy_set_header   Connection keep-alive;\n        proxy_set_header   Host $host;\n        proxy_cache_bypass $http_upgrade;\n    }\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reload Nginx:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nginx -s reload\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>4\ufe0f\u20e3 Ch\u1ea1y \u1ee9ng d\u1ee5ng tr\u00ean CentOS Ch\u1ea1y tr\u1ef1c ti\u1ebfp Ch\u1ea1y \u1edf ch\u1ebf \u0111\u1ed9 production 5\ufe0f\u20e3 C\u00e0i \u0111\u1eb7t d\u1ecbch v\u1ee5 systemd \u0111\u1ec3 ch\u1ea1y t\u1ef1 \u0111\u1ed9ng T\u1ea1o <a class=\"mh-excerpt-more\" href=\"https:\/\/blogs.giamkichsan.com\/index.php\/2025\/11\/15\/build-va-chay-mot-ung-dung-web-net-core-net-6-7-8-tren-centos\/\" title=\"Build v\u00e0 ch\u1ea1y m\u1ed9t \u1ee9ng d\u1ee5ng Web .NET Core (.NET 6\/7\/8) tr\u00ean CentOS\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-64","post","type-post","status-publish","format-standard","hentry","category-centos-he-dieu-hanh"],"_links":{"self":[{"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":3,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}