{"id":130,"date":"2025-12-20T02:58:32","date_gmt":"2025-12-20T02:58:32","guid":{"rendered":"https:\/\/blogs.giamkichsan.com\/?p=130"},"modified":"2025-12-20T02:58:33","modified_gmt":"2025-12-20T02:58:33","slug":"nginxcai-dat-app-tren-ubuntu","status":"publish","type":"post","link":"https:\/\/blogs.giamkichsan.com\/index.php\/2025\/12\/20\/nginxcai-dat-app-tren-ubuntu\/","title":{"rendered":"[NGINX]C\u00e0i \u0111\u1eb7t app tr\u00ean ubuntu"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1\ufe0f\u20e3 C\u00e0i Nginx (n\u1ebfu ch\u01b0a c\u00f3)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install nginx -y\n<\/code><\/pre>\n\n\n\n<p>Ki\u1ec3m tra Nginx:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status nginx\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\">2\ufe0f\u20e3 C\u1ea5u tr\u00fac c\u01a1 b\u1ea3n reverse proxy<\/h2>\n\n\n\n<p>Reverse proxy ngh\u0129a l\u00e0: <strong>Nginx nh\u1eadn request t\u1eeb client \u2192 chuy\u1ec3n ti\u1ebfp \u0111\u1ebfn backend (app server)<\/strong><\/p>\n\n\n\n<p>V\u00ed d\u1ee5:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Client truy c\u1eadp <code>http:\/\/yourdomain.com<\/code><\/li>\n\n\n\n<li>Nginx chuy\u1ec3n request t\u1edbi <code>http:\/\/localhost:5000<\/code> (app .NET \/ Node.js \/ Python\u2026)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3\ufe0f\u20e3 T\u1ea1o file c\u1ea5u h\u00ecnh site m\u1edbi<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/nginx\/sites-available\/myapp\n<\/code><\/pre>\n\n\n\n<p>V\u00ed d\u1ee5 c\u1ea5u h\u00ecnh c\u01a1 b\u1ea3n:<\/p>\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<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4\ufe0f\u20e3 K\u00edch ho\u1ea1t site<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ln -s \/etc\/nginx\/sites-available\/myapp \/etc\/nginx\/sites-enabled\/\n<\/code><\/pre>\n\n\n\n<p>Ki\u1ec3m tra c\u1ea5u h\u00ecnh:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nginx -t\n<\/code><\/pre>\n\n\n\n<p>Reload Nginx:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl reload nginx\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\">5\ufe0f\u20e3 Ki\u1ec3m tra reverse proxy<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>App backend ch\u1ea1y \u1edf <code>localhost:5000<\/code>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>curl http:\/\/127.0.0.1:5000\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Truy c\u1eadp domain:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;yourdomain.com\n<\/code><\/pre>\n\n\n\n<p>Nginx s\u1ebd chuy\u1ec3n request t\u1edbi backend.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6\ufe0f\u20e3 (T\u00f9y ch\u1ecdn) B\u1eadt HTTPS v\u1edbi Let\u2019s Encrypt<\/h2>\n\n\n\n<p>C\u00e0i certbot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install certbot python3-certbot-nginx -y\n<\/code><\/pre>\n\n\n\n<p>C\u1ea5p ch\u1ee9ng ch\u1ec9 SSL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo certbot --nginx -d yourdomain.com\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>1\ufe0f\u20e3 C\u00e0i Nginx (n\u1ebfu ch\u01b0a c\u00f3) Ki\u1ec3m tra Nginx: 2\ufe0f\u20e3 C\u1ea5u tr\u00fac c\u01a1 b\u1ea3n reverse proxy Reverse proxy ngh\u0129a l\u00e0: Nginx nh\u1eadn request t\u1eeb client <a class=\"mh-excerpt-more\" href=\"https:\/\/blogs.giamkichsan.com\/index.php\/2025\/12\/20\/nginxcai-dat-app-tren-ubuntu\/\" title=\"[NGINX]C\u00e0i \u0111\u1eb7t app tr\u00ean ubuntu\">[&#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":[12],"tags":[],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-ubuntu-he-dieu-hanh"],"_links":{"self":[{"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/posts\/130","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=130"}],"version-history":[{"count":1,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":131,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions\/131"}],"wp:attachment":[{"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.giamkichsan.com\/index.php\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}