{"id":3979,"date":"2024-02-23T10:01:18","date_gmt":"2024-02-23T03:01:18","guid":{"rendered":"https:\/\/longvan.net\/cong-dong\/?p=3979"},"modified":"2024-03-13T14:53:21","modified_gmt":"2024-03-13T07:53:21","slug":"huong-dan-toi-uu-cau-hinh-apache-cho-website-co-luu-luong-truy-cap-cao","status":"publish","type":"post","link":"https:\/\/longvan.net\/cong-dong\/huong-dan-toi-uu-cau-hinh-apache-cho-website-co-luu-luong-truy-cap-cao\/","title":{"rendered":"H\u01b0\u1edbng d\u1eabn t\u1ed1i \u01b0u c\u1ea5u h\u00ecnh Apache cho website c\u00f3 l\u01b0u l\u01b0\u1ee3ng truy c\u1eadp cao"},"content":{"rendered":"<p>N\u1ebfu b\u1ea1n \u0111ang ch\u1ea1y m\u1ed9t trang web nh\u1eadn \u0111\u01b0\u1ee3c nhi\u1ec1u l\u01b0u l\u01b0\u1ee3ng truy c\u1eadp, \u0111i\u1ec1u c\u1ea7n thi\u1ebft l\u00e0 ph\u1ea3i t\u1ed1i \u01b0u h\u00f3a c\u1ea5u h\u00ecnh m\u00e1y ch\u1ee7 web Apache c\u1ee7a b\u1ea1n \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o hi\u1ec7u su\u1ea5t v\u00e0 t\u00ednh kh\u1ea3 d\u1ee5ng t\u1ed1i \u0111a. Trong b\u00e0i vi\u1ebft n\u00e0y, Long V\u00e2n s\u1ebd cung c\u1ea5p cho b\u1ea1n m\u1ed9t s\u1ed1 m\u1eb9o v\u00e0 v\u00ed d\u1ee5 v\u1ec1 c\u00e1ch t\u1ed1i \u01b0u h\u00f3a c\u1ea5u h\u00ecnh Apache c\u1ee7a b\u1ea1n cho c\u00e1c trang web c\u00f3 l\u01b0u l\u01b0\u1ee3ng truy c\u1eadp cao.<\/p>\n<h2 class=\"wp-block-heading\">I. S\u1eed d\u1ee5ng module MPM ph\u00f9 h\u1ee3p<\/h2>\n<p>Apache s\u1eed d\u1ee5ng Multi-Processing Modules (MPM) \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c y\u00eau c\u1ea7u c\u1ee7a client. MPM ch\u1ecbu tr\u00e1ch nhi\u1ec7m t\u1ea1o c\u00e1c ti\u1ebfn tr\u00ecnh ho\u1eb7c lu\u1ed3ng con \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c y\u00eau c\u1ea7u \u0111\u1ebfn.\u00a0C\u00f3 ba module MPM c\u00f3 s\u1eb5n trong Apache: <code>prefork<\/code>,\u00a0<code>worker<\/code>v\u00e0\u00a0<code>event<\/code>.<\/p>\n<ul>\n<li>MPM\u00a0<code>prefork<\/code>l\u00e0 module MPM l\u00e2u \u0111\u1eddi nh\u1ea5t v\u00e0 \u1ed5n \u0111\u1ecbnh nh\u1ea5t. N\u00f3 t\u1ea1o ra m\u1ed9t ti\u1ebfn tr\u00ecnh cho m\u1ed7i k\u1ebft n\u1ed1i, \u0111i\u1ec1u n\u00e0y c\u00f3 th\u1ec3 d\u1eabn \u0111\u1ebfn vi\u1ec7c s\u1eed d\u1ee5ng nhi\u1ec1u t\u00e0i nguy\u00ean.<\/li>\n<li>MPM\u00a0<code>worker<\/code>t\u1ea1o nhi\u1ec1u lu\u1ed3ng cho m\u1ed7i ti\u1ebfn tr\u00ecnh, c\u00f3 th\u1ec3 c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t v\u00e0 gi\u1ea3m m\u1ee9c s\u1eed d\u1ee5ng t\u00e0i nguy\u00ean.<\/li>\n<li>MPM\u00a0<code>event<\/code>t\u01b0\u01a1ng t\u1ef1 nh\u01b0\u00a0<code>worker<\/code>MPM, nh\u01b0ng n\u00f3 b\u1ed5 sung c\u01a1 ch\u1ebf th\u00f4ng b\u00e1o s\u1ef1 ki\u1ec7n kh\u00f4ng \u0111\u1ed3ng b\u1ed9 \u0111\u1ec3 c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t h\u01a1n n\u1eefa.<\/li>\n<\/ul>\n<p>\u0110\u1ec3 t\u1ed1i \u01b0u h\u00f3a c\u1ea5u h\u00ecnh Apache c\u1ee7a b\u1ea1n \u0111\u1ec3 c\u00f3 l\u01b0u l\u01b0\u1ee3ng truy c\u1eadp cao, ch\u00fang t\u00f4i khuy\u00ean b\u1ea1n n\u00ean s\u1eed d\u1ee5ng module <code>worker<\/code> ho\u1eb7c\u00a0<code>event<\/code> MPM.\u00a0B\u1ea1n c\u00f3 th\u1ec3 k\u00edch ho\u1ea1t c\u00e1c m\u00f4-\u0111un n\u00e0y b\u1eb1ng c\u00e1ch b\u1ecf # c\u00e1c d\u00f2ng sau trong t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh:<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-inline property\">LoadModule<\/span> mpm_worker_module modules\/mod_mpm_worker.so<\/code><\/pre>\n<p>ho\u1eb7c<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-inline property\">LoadModule<\/span> mpm_event_module modules\/mod_mpm_event.so<\/code><\/pre>\n<h2 class=\"wp-block-heading\">II. T\u0103ng s\u1ed1 l\u01b0\u1ee3ng ti\u1ebfn tr\u00ecnh\/lu\u1ed3ng con<\/h2>\n<p>\u0110\u1ec3 x\u1eed l\u00fd kh\u1ed1i l\u01b0\u1ee3ng l\u1edbn y\u00eau c\u1ea7u g\u1eedi \u0111\u1ebfn, b\u1ea1n c\u1ea7n t\u0103ng s\u1ed1 l\u01b0\u1ee3ng ti\u1ebfn tr\u00ecnh ho\u1eb7c lu\u1ed3ng con m\u00e0 Apache c\u00f3 th\u1ec3 t\u1ea1o.\u00a0S\u1ed1 l\u01b0\u1ee3ng ti\u1ebfn tr\u00ecnh ho\u1eb7c lu\u1ed3ng con b\u1ea1n n\u00ean t\u1ea1o t\u00f9y thu\u1ed9c v\u00e0o l\u01b0\u1ee3ng b\u1ed9 nh\u1edb v\u00e0 t\u00e0i nguy\u00ean CPU c\u00f3 s\u1eb5n tr\u00ean m\u00e1y ch\u1ee7 c\u1ee7a b\u1ea1n.<\/p>\n<p>\u0110\u1ec3 t\u0103ng s\u1ed1 l\u01b0\u1ee3ng ti\u1ebfn tr\u00ecnh ho\u1eb7c lu\u1ed3ng con, b\u1ea1n c\u1ea7n s\u1eeda \u0111\u1ed5i c\u00e1c gi\u00e1 tr\u1ecb <code>StartServers<\/code>,\u00a0\u00a0<code>MaxClients<\/code>,\u00a0\u00a0<code>MaxSpareServers<\/code>v\u00e0\u00a0\u00a0<code>MinSpareServers<\/code>\u00a0trong t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh.<\/p>\n<p><code>StartServers<\/code>\u00a0l\u00e0 s\u1ed1 ti\u1ebfn tr\u00ecnh con \u0111\u01b0\u1ee3c kh\u1edfi ch\u1ea1y khi Apache kh\u1edfi \u0111\u1ed9ng.\u00a0<code>MaxClients<\/code>\u00a0l\u00e0 s\u1ed1 l\u01b0\u1ee3ng k\u1ebft n\u1ed1i \u0111\u1ed3ng th\u1eddi t\u1ed1i \u0111a m\u00e0 Apache c\u00f3 th\u1ec3 x\u1eed l\u00fd.\u00a0<code>MaxSpareServers<\/code>\u00a0l\u00e0 s\u1ed1 ti\u1ebfn tr\u00ecnh con nh\u00e0n r\u1ed7i t\u1ed1i \u0111a m\u00e0 Apache duy tr\u00ec.\u00a0<code>MinSpareServers<\/code>\u00a0l\u00e0 s\u1ed1 ti\u1ebfn tr\u00ecnh con nh\u00e0n r\u1ed7i t\u1ed1i thi\u1ec3u m\u00e0 Apache duy tr\u00ec.<\/p>\n<p>V\u00ed d\u1ee5: \u0111\u1ec3 \u0111\u1eb7t\u00a0\u00a0<code>StartServers<\/code>\u00a0th\u00e0nh 10,\u00a0\u00a0<code>MaxClients<\/code>\u00a0th\u00e0nh 500,\u00a0\u00a0<code>MaxSpareServers<\/code>\u00a0th\u00e0nh 200 v\u00e0\u00a0\u00a0<code>MinSpareServers<\/code>\u00a0th\u00e0nh 10, b\u1ea1n c\u00f3 th\u1ec3 th\u00eam c\u00e1c d\u00f2ng sau v\u00e0o t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh:<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-inline property\">StartServers<\/span> 10\nMaxClients 500\n<span class=\"token directive-inline property\">MaxSpareServers<\/span> 200\n<span class=\"token directive-inline property\">MinSpareServers<\/span> 10<\/code><\/pre>\n<p>B\u1ea1n c\u0169ng n\u00ean c\u00e2n nh\u1eafc vi\u1ec7c \u0111\u1eb7t\u00a0\u00a0<code>ServerLimit<\/code>c\u00f3 c\u00f9ng gi\u00e1 tr\u1ecb v\u1edbi\u00a0\u00a0<code>MaxClients<\/code>.\u00a0\u0110i\u1ec1u n\u00e0y \u0111\u1ea3m b\u1ea3o r\u1eb1ng Apache kh\u00f4ng t\u1ea1o ra nhi\u1ec1u ti\u1ebfn tr\u00ecnh con h\u01a1n m\u1ee9c c\u1ea7n thi\u1ebft.<\/p>\n<p>M\u1ed9t tham s\u1ed1 quan tr\u1ecdng kh\u00e1c c\u00f3 th\u1ec3 gi\u00fap t\u0103ng s\u1ed1 l\u01b0\u1ee3ng ti\u1ebfn tr\u00ecnh\/lu\u1ed3ng con trong Apache l\u00e0 gi\u00e1 tr\u1ecb\u00a0 <code>MaxRequestWorkers<\/code> . Gi\u00e1 tr\u1ecb\u00a0n\u00e0y ch\u1ec9 \u0111\u1ecbnh s\u1ed1 l\u01b0\u1ee3ng y\u00eau c\u1ea7u \u0111\u1ed3ng th\u1eddi t\u1ed1i \u0111a m\u00e0 Apache c\u00f3 th\u1ec3 x\u1eed l\u00fd.<\/p>\n<p>Theo m\u1eb7c \u0111\u1ecbnh,\u00a0\u00a0<code>MaxRequestWorkers<\/code>\u00a0gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c \u0111\u1eb7t th\u00e0nh 256. Tuy nhi\u00ean, gi\u00e1 tr\u1ecb n\u00e0y c\u00f3 th\u1ec3 t\u0103ng l\u00ean \u0111\u1ec3 cho ph\u00e9p Apache x\u1eed l\u00fd \u0111\u1ed3ng th\u1eddi nhi\u1ec1u y\u00eau c\u1ea7u h\u01a1n.<\/p>\n<p>\u0110\u1ec3 \u0111i\u1ec1u ch\u1ec9nh\u00a0\u00a0<code>MaxRequestWorkers<\/code>\u00a0gi\u00e1 tr\u1ecb, b\u1ea1n c\u00f3 th\u1ec3 th\u00eam d\u00f2ng sau v\u00e0o t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh:<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-inline property\">MaxRequestWorkers<\/span> 500<\/code><\/pre>\n<p>Trong v\u00ed d\u1ee5 tr\u00ean, ch\u00fang t\u00f4i \u0111\u00e3 \u0111\u1eb7t\u00a0\u00a0<code>MaxRequestWorkers<\/code>\u00a0gi\u00e1 tr\u1ecb th\u00e0nh 500, c\u00f3 ngh\u0129a l\u00e0 Apache c\u00f3 th\u1ec3 x\u1eed l\u00fd t\u1ed1i \u0111a 500 y\u00eau c\u1ea7u \u0111\u1ed3ng th\u1eddi.<\/p>\n<p>\u0110i\u1ec1u quan tr\u1ecdng c\u1ea7n l\u01b0u \u00fd l\u00e0 vi\u1ec7c t\u0103ng\u00a0\u00a0<code>MaxRequestWorkers<\/code>\u00a0gi\u00e1 tr\u1ecb c\u0169ng l\u00e0m t\u0103ng dung l\u01b0\u1ee3ng b\u1ed9 nh\u1edb \u0111\u01b0\u1ee3c Apache s\u1eed d\u1ee5ng.\u00a0Do \u0111\u00f3, b\u1ea1n n\u00ean \u0111\u1ea3m b\u1ea3o r\u1eb1ng m\u00e1y ch\u1ee7 c\u1ee7a b\u1ea1n c\u00f3 \u0111\u1ee7 b\u1ed9 nh\u1edb \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c y\u00eau c\u1ea7u b\u1ed5 sung.<\/p>\n<h2 class=\"wp-block-heading\">III. K\u00edch ho\u1ea1t KeepAlive<\/h2>\n<p>T\u00ednh n\u0103ng KeepAlive cho ph\u00e9p client s\u1eed d\u1ee5ng l\u1ea1i c\u00f9ng m\u1ed9t k\u1ebft n\u1ed1i v\u1edbi m\u00e1y ch\u1ee7 cho nhi\u1ec1u y\u00eau c\u1ea7u, gi\u1ea3m chi ph\u00ed t\u1ea1o k\u1ebft n\u1ed1i m\u1edbi cho m\u1ed7i y\u00eau c\u1ea7u. K\u00edch ho\u1ea1t KeepAlive c\u00f3 th\u1ec3 c\u1ea3i thi\u1ec7n \u0111\u00e1ng k\u1ec3 hi\u1ec7u su\u1ea5t trang web c\u1ee7a b\u1ea1n.<\/p>\n<p>\u0110\u1ec3 b\u1eadt KeepAlive, b\u1ea1n c\u1ea7n \u0111\u1eb7t\u00a0<code>KeepAlive<\/code>\u00a0th\u00e0nh\u00a0<code>On<\/code>.\u00a0B\u1ea1n c\u0169ng n\u00ean \u0111\u1eb7t\u00a0<code>KeepAliveTimeout<\/code>\u00a0th\u00e0nh m\u1ed9t gi\u00e1 tr\u1ecb ph\u00f9 h\u1ee3p v\u1edbi trang web c\u1ee7a m\u00ecnh. V\u00ed d\u1ee5: \u0111\u1ec3 \u0111\u1eb7t th\u1eddi gian ch\u1edd KeepAlive th\u00e0nh 5 gi\u00e2y, b\u1ea1n c\u00f3 th\u1ec3 th\u00eam c\u00e1c d\u00f2ng sau v\u00e0o t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh:<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-inline property\">KeepAlive<\/span> On\n<span class=\"token directive-inline property\">KeepAliveTimeout<\/span> 5\n<span class=\"token directive-inline property\">MaxKeepAliveRequests<\/span> 100 <\/code><\/pre>\n<h2 class=\"wp-block-heading\">IV. K\u00edch ho\u1ea1t b\u1ed9 nh\u1edb \u0111\u1ec7m<\/h2>\n<p>B\u1ed9 nh\u1edb \u0111\u1ec7m l\u00e0 qu\u00e1 tr\u00ecnh l\u01b0u tr\u1eef d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c truy c\u1eadp th\u01b0\u1eddng xuy\u00ean trong b\u1ed9 nh\u1edb ho\u1eb7c tr\u00ean \u0111\u0129a, gi\u1ea3m s\u1ed1 l\u01b0\u1ee3ng y\u00eau c\u1ea7u c\u1ea7n \u0111\u01b0\u1ee3c m\u00e1y ch\u1ee7 x\u1eed l\u00fd.\u00a0K\u00edch ho\u1ea1t b\u1ed9 nh\u1edb \u0111\u1ec7m c\u00f3 th\u1ec3 c\u1ea3i thi\u1ec7n \u0111\u00e1ng k\u1ec3 hi\u1ec7u su\u1ea5t trang web c\u1ee7a b\u1ea1n, \u0111\u1eb7c bi\u1ec7t \u0111\u1ed1i v\u1edbi n\u1ed9i dung t\u0129nh.<\/p>\n<p>Apache cung c\u1ea5p m\u1ed9t s\u1ed1 module b\u1ed9 nh\u1edb \u0111\u1ec7m, ch\u1eb3ng h\u1ea1n nh\u01b0 <code>mod_cache<\/code>v\u00e0\u00a0<code>mod_disk_cache<\/code>.\u00a0\u0110\u1ec3 b\u1eadt b\u1ed9 nh\u1edb \u0111\u1ec7m, b\u1ea1n c\u1ea7n t\u1ea3i module b\u1ed9 nh\u1edb \u0111\u1ec7m th\u00edch h\u1ee3p v\u00e0 \u0111\u1ecbnh c\u1ea5u h\u00ecnh n\u00f3 trong t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a b\u1ea1n. V\u00ed d\u1ee5: \u0111\u1ec3 b\u1eadt b\u1ed9 nh\u1edb \u0111\u1ec7m n\u1ed9i dung t\u0129nh b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng\u00a0<code>mod_disk_cache<\/code>, b\u1ea1n c\u00f3 th\u1ec3 th\u00eam c\u00e1c d\u00f2ng sau v\u00e0o t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh:<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-inline property\">LoadModule<\/span> cache_module modules\/mod_cache.so\n<span class=\"token directive-inline property\">LoadModule<\/span> disk_cache_module modules\/mod_disk_cache.so\n<span class=\"token directive-inline property\">CacheEnable<\/span> disk \/\n<span class=\"token directive-inline property\">CacheRoot<\/span> \/var\/cache\/apache2\/mod_disk_cache\n<span class=\"token directive-inline property\">CacheDirLevels<\/span> 2\n<span class=\"token directive-inline property\">CacheDirLength<\/span> 1<\/code><\/pre>\n<p>Nh\u1eefng d\u00f2ng n\u00e0y k\u00edch ho\u1ea1t c\u00e1c module <code>mod_cache<\/code>v\u00e0\u00a0<code>mod_disk_cache<\/code>v\u00e0 \u0111\u1ecbnh c\u1ea5u h\u00ecnh b\u1ed9 nh\u1edb \u0111\u1ec7m cho th\u01b0 m\u1ee5c g\u1ed1c (\u00a0<code>\/<\/code>) b\u1eb1ng b\u1ed9 \u0111\u1ec7m \u0111\u0129a.\u00a0L\u1ec7nh n\u00e0y\u00a0<code>CacheRoot<\/code>ch\u1ec9 \u0111\u1ecbnh th\u01b0 m\u1ee5c n\u01a1i n\u1ed9i dung \u0111\u01b0\u1ee3c l\u01b0u trong b\u1ed9 \u0111\u1ec7m s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef, \u0111\u1ed3ng th\u1eddi\u00a0<code>CacheDirLevels<\/code>v\u00e0 <code>CacheDirLength<\/code>ki\u1ec3m so\u00e1t c\u1ea5u tr\u00fac ph\u00e2n c\u1ea5p th\u01b0 m\u1ee5c b\u1ed9 \u0111\u1ec7m.<\/p>\n<h2 class=\"wp-block-heading\">V. S\u1eed d\u1ee5ng t\u00ednh n\u0103ng n\u00e9n d\u1eef li\u1ec7u trong Apache<\/h2>\n<p>N\u00e9n l\u00e0 qu\u00e1 tr\u00ecnh gi\u1ea3m k\u00edch th\u01b0\u1edbc d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c g\u1eedi qua m\u1ea1ng b\u1eb1ng c\u00e1ch lo\u1ea1i b\u1ecf th\u00f4ng tin d\u01b0 th\u1eeba.\u00a0Vi\u1ec7c k\u00edch ho\u1ea1t t\u00ednh n\u0103ng n\u00e9n c\u00f3 th\u1ec3 l\u00e0m gi\u1ea3m \u0111\u00e1ng k\u1ec3 l\u01b0\u1ee3ng d\u1eef li\u1ec7u c\u1ea7n truy\u1ec1n \u0111i, c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t trang web c\u1ee7a b\u1ea1n.<\/p>\n<p>Apache cung c\u1ea5p m\u1ed9t module n\u00e9n c\u00f3 t\u00ean <code>mod_deflate<\/code>.\u00a0\u0110\u1ec3 b\u1eadt t\u00ednh n\u0103ng n\u00e9n, b\u1ea1n c\u1ea7n t\u1ea3i\u00a0<code>mod_deflate<\/code>module v\u00e0 \u0111\u1ecbnh c\u1ea5u h\u00ecnh n\u00f3 trong t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh.<\/p>\n<p>V\u00ed d\u1ee5: \u0111\u1ec3 b\u1eadt t\u00ednh n\u0103ng n\u00e9n n\u1ed9i dung d\u1ef1a tr\u00ean v\u0103n b\u1ea3n, b\u1ea1n c\u00f3 th\u1ec3 th\u00eam c\u00e1c d\u00f2ng sau v\u00e0o t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh:<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-inline property\">LoadModule<\/span> deflate_module modules\/mod_deflate.so\n<span class=\"token directive-inline property\">AddOutputFilterByType<\/span> DEFLATE text\/html text\/plain text\/xml text\/css application\/javascript application\/json<\/code><\/pre>\n<p>Nh\u1eefng d\u00f2ng n\u00e0y k\u00edch ho\u1ea1t\u00a0<code>mod_deflate<\/code> m\u00f4-\u0111un v\u00e0 ch\u1ec9 \u0111\u1ecbnh lo\u1ea1i n\u1ed9i dung c\u1ea7n \u0111\u01b0\u1ee3c n\u00e9n.<\/p>\n<h2 class=\"wp-block-heading\">VI. H\u1ea1n ch\u1ebf quy\u1ec1n truy c\u1eadp v\u00e0o t\u00e0i nguy\u00ean<\/h2>\n<p>Vi\u1ec7c h\u1ea1n ch\u1ebf quy\u1ec1n truy c\u1eadp v\u00e0o t\u00e0i nguy\u00ean c\u00f3 th\u1ec3 gi\u00fap gi\u1ea3m t\u1ea3i cho m\u00e1y ch\u1ee7 v\u00e0 c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t trang web c\u1ee7a b\u1ea1n.\u00a0B\u1ea1n c\u00f3 th\u1ec3 gi\u1edbi h\u1ea1n quy\u1ec1n truy c\u1eadp v\u00e0o t\u00e0i nguy\u00ean b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh\u00a0<code>Order<\/code>,\u00a0<code>Allow<\/code>v\u00e0\u00a0<code>Deny<\/code>trong t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh.<\/p>\n<p>V\u00ed d\u1ee5: \u0111\u1ec3 gi\u1edbi h\u1ea1n quy\u1ec1n truy c\u1eadp v\u00e0o th\u01b0 m\u1ee5c c\u00f3 t\u00ean\u00a0<code>admin<\/code>, b\u1ea1n c\u00f3 th\u1ec3 th\u00eam c\u00e1c d\u00f2ng sau v\u00e0o t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a m\u00ecnh:<\/p>\n<pre class=\"wp-block-code language-apacheconf\"><code class=\"language-apacheconf\"><span class=\"token directive-block tag\"><span class=\"token punctuation\">&lt;<\/span>Directory<span class=\"token directive-block-parameter attr-value\"> \/var\/www\/html\/admin<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>\n    <span class=\"token directive-inline property\">Order<\/span> <span class=\"token directive-inline property\">deny<\/span>,allow\n    <span class=\"token directive-inline property\">Deny<\/span> from all\n    <span class=\"token directive-inline property\">Allow<\/span> from 192.168.0.0\/24\n<span class=\"token directive-block tag\"><span class=\"token punctuation\">&lt;\/<\/span>Directory<span class=\"token punctuation\">&gt;<\/span><\/span><\/code><\/pre>\n<p>Nh\u1eefng d\u00f2ng n\u00e0y ch\u1ec9 \u0111\u1ecbnh r\u1eb1ng quy\u1ec1n truy c\u1eadp v\u00e0o\u00a0<code>admin<\/code>th\u01b0 m\u1ee5c s\u1ebd b\u1ecb t\u1eeb ch\u1ed1i \u0111\u1ed1i v\u1edbi t\u1ea5t c\u1ea3 c\u00e1c m\u00e1y kh\u00e1ch ngo\u1ea1i tr\u1eeb nh\u1eefng m\u00e1y kh\u00e1ch trong\u00a0<code>192.168.0.0\/24<\/code>m\u1ea1ng con.<\/p>\n<h2 id=\"7-optimize-server-resources\" class=\"wp-block-heading\">VII. T\u1ed1i \u01b0u h\u00f3a t\u00e0i nguy\u00ean m\u00e1y ch\u1ee7<\/h2>\n<p>Ngo\u00e0i vi\u1ec7c t\u1ed1i \u01b0u h\u00f3a Apache, b\u1ea1n c\u0169ng c\u00f3 th\u1ec3 t\u1ed1i \u01b0u h\u00f3a t\u00e0i nguy\u00ean m\u00e1y ch\u1ee7 \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o hi\u1ec7u su\u1ea5t v\u00e0 t\u00ednh kh\u1ea3 d\u1ee5ng t\u1ed1i \u0111a cho trang web c\u1ee7a m\u00ecnh.<\/p>\n<h3 id=\"a-increase-memory-limit-and-set-opcache\" class=\"wp-block-heading\">1. T\u0103ng gi\u1edbi h\u1ea1n b\u1ed9 nh\u1edb v\u00e0 \u0111\u1eb7t Opcache<\/h3>\n<p>Gi\u1edbi h\u1ea1n b\u1ed9 nh\u1edb m\u1eb7c \u0111\u1ecbnh c\u1ee7a t\u1eadp l\u1ec7nh PHP c\u00f3 th\u1ec3 kh\u00f4ng \u0111\u1ee7 \u0111\u1ec3 x\u1eed l\u00fd kh\u1ed1i l\u01b0\u1ee3ng l\u1edbn y\u00eau c\u1ea7u g\u1eedi \u0111\u1ebfn.\u00a0B\u1ea1n c\u00f3 th\u1ec3 t\u0103ng gi\u1edbi h\u1ea1n b\u1ed9 nh\u1edb b\u1eb1ng c\u00e1ch s\u1eeda \u0111\u1ed5i\u00a0\u00a0<code>memory_limit<\/code>\u00a0l\u1ec7nh trong t\u1ec7p c\u1ea5u h\u00ecnh PHP c\u1ee7a m\u00ecnh.<\/p>\n<p>Ngo\u00e0i ra, b\u1ea1n c\u0169ng c\u00f3 th\u1ec3 k\u00edch ho\u1ea1t Opcache, \u0111\u00e2y l\u00e0 b\u1ed9 \u0111\u1ec7m m\u00e3 byte cho c\u00e1c t\u1eadp l\u1ec7nh PHP.\u00a0Opcache l\u01b0u tr\u1eef bytecode t\u1eadp l\u1ec7nh \u0111\u01b0\u1ee3c bi\u00ean d\u1ecbch s\u1eb5n trong b\u1ed9 nh\u1edb, gi\u1ea3m chi ph\u00ed ph\u00e2n t\u00edch c\u00fa ph\u00e1p v\u00e0 bi\u00ean d\u1ecbch t\u1eadp l\u1ec7nh cho m\u1ecdi y\u00eau c\u1ea7u.<\/p>\n<h5 id=\"install-opcache\" class=\"wp-block-heading\">C\u00e0i \u0111\u1eb7t OPCache<\/h5>\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\"><span class=\"token comment\"># For CentOS, RedHat and Alma Linux use this command :<\/span>\n$ <span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> php-opcache\n<span class=\"token comment\"># For Ubuntu and Debian use this command :<\/span>\n$ <span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> <span class=\"token function\">install<\/span> php-opcache<\/code><\/pre>\n<p>Sau khi qu\u00e1 tr\u00ecnh c\u00e0i \u0111\u1eb7t ho\u00e0n t\u1ea5t, h\u00e3y kh\u1edfi \u0111\u1ed9ng l\u1ea1i Apache \u0111\u1ec3 \u00e1p d\u1ee5ng c\u00e1c thay \u0111\u1ed5i:<\/p>\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">sudo<\/span> systemctl restart apache2<\/code><\/pre>\n<p>\u0110\u00f3 l\u00e0 n\u00f3!\u00a0OPcache b\u00e2y gi\u1edd s\u1ebd \u0111\u01b0\u1ee3c c\u00e0i \u0111\u1eb7t v\u00e0 k\u00edch ho\u1ea1t tr\u00ean h\u1ec7 th\u1ed1ng Ubuntu c\u1ee7a b\u1ea1n.\u00a0B\u1ea1n c\u00f3 th\u1ec3 x\u00e1c minh r\u1eb1ng n\u00f3 \u0111\u00e3 \u0111\u01b0\u1ee3c b\u1eadt b\u1eb1ng c\u00e1ch ki\u1ec3m tra c\u1ea5u h\u00ecnh PHP c\u1ee7a b\u1ea1n.<\/p>\n<h3 id=\"b-set-up-a-swap-file-or-swap-partition\" class=\"wp-block-heading\">2. Thi\u1ebft l\u1eadp t\u1ec7p Ho\u00e1n \u0111\u1ed5i ho\u1eb7c ph\u00e2n v\u00f9ng Ho\u00e1n \u0111\u1ed5i<\/h3>\n<p>N\u1ebfu m\u00e1y ch\u1ee7 c\u1ee7a b\u1ea1n h\u1ebft b\u1ed9 nh\u1edb, n\u00f3 c\u00f3 th\u1ec3 b\u1eaft \u0111\u1ea7u s\u1eed d\u1ee5ng \u0111\u0129a c\u1ee9ng l\u00e0m b\u1ed9 nh\u1edb \u1ea3o, \u0111i\u1ec1u n\u00e0y c\u00f3 th\u1ec3 l\u00e0m gi\u1ea3m \u0111\u00e1ng k\u1ec3 hi\u1ec7u su\u1ea5t trang web c\u1ee7a b\u1ea1n.\u00a0B\u1ea1n c\u00f3 th\u1ec3 tr\u00e1nh \u0111i\u1ec1u n\u00e0y b\u1eb1ng c\u00e1ch thi\u1ebft l\u1eadp t\u1ec7p Ho\u00e1n \u0111\u1ed5i ho\u1eb7c ph\u00e2n v\u00f9ng Ho\u00e1n \u0111\u1ed5i, cung c\u1ea5p th\u00eam b\u1ed9 nh\u1edb \u1ea3o khi b\u1ed9 nh\u1edb v\u1eadt l\u00fd c\u1ea1n ki\u1ec7t.<\/p>\n<p>\u0110\u1ec3 thi\u1ebft l\u1eadp t\u1ec7p Ho\u00e1n \u0111\u1ed5i, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh sau:<\/p>\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">sudo<\/span> fallocate -l 1G \/swapfile\n$ <span class=\"token function\">sudo<\/span> <span class=\"token function\">chmod<\/span> 600 \/swapfile\n$ <span class=\"token function\">sudo<\/span> <span class=\"token function\">mkswap<\/span> \/swapfile\n$ <span class=\"token function\">sudo<\/span> <span class=\"token function\">swapon<\/span> \/swapfile<\/code><\/pre>\n<p>C\u00e1c l\u1ec7nh n\u00e0y t\u1ea1o t\u1ec7p Ho\u00e1n \u0111\u1ed5i 1GB, \u0111\u1eb7t quy\u1ec1n cho t\u1ec7p, \u0111\u1ecbnh d\u1ea1ng t\u1ec7p l\u00e0 Ho\u00e1n \u0111\u1ed5i v\u00e0 b\u1eadt Ho\u00e1n \u0111\u1ed5i.<\/p>\n<h3 id=\"c-enable-gzip-compression\" class=\"wp-block-heading\">3. K\u00edch ho\u1ea1t t\u00ednh n\u0103ng n\u00e9n GZIP<\/h3>\n<p>K\u00edch ho\u1ea1t t\u00ednh n\u0103ng n\u00e9n GZIP c\u00f3 th\u1ec3 gi\u1ea3m k\u00edch th\u01b0\u1edbc d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c truy\u1ec1n qua m\u1ea1ng, c\u1ea3i thi\u1ec7n hi\u1ec7u su\u1ea5t trang web c\u1ee7a b\u1ea1n.\u00a0B\u1ea1n c\u00f3 th\u1ec3 k\u00edch ho\u1ea1t t\u00ednh n\u0103ng n\u00e9n GZIP b\u1eb1ng c\u00e1ch t\u1ea3i\u00a0\u00a0<code>deflate<\/code>module trong Apache v\u00e0 \u0111\u1ecbnh c\u1ea5u h\u00ecnh n\u00f3 trong t\u1ec7p c\u1ea5u h\u00ecnh Apache c\u1ee7a b\u1ea1n.<\/p>\n<p>\u0110\u1ec3 b\u1eadt t\u00ednh n\u0103ng n\u00e9n GZIP, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh sau:<\/p>\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">sudo<\/span> a2enmod deflate\n$ <span class=\"token function\">sudo<\/span> <span class=\"token function\">service<\/span> apache2 restart<\/code><\/pre>\n<p>C\u00e1c l\u1ec7nh n\u00e0y k\u00edch ho\u1ea1t\u00a0\u00a0<code>deflate<\/code>\u00a0m\u00f4-\u0111un trong Apache v\u00e0 kh\u1edfi \u0111\u1ed9ng l\u1ea1i d\u1ecbch v\u1ee5 Apache.\u00a0Sau khi\u00a0\u00a0<code>deflate<\/code>\u00a0m\u00f4-\u0111un \u0111\u01b0\u1ee3c b\u1eadt, Apache s\u1ebd t\u1ef1 \u0111\u1ed9ng n\u00e9n n\u1ed9i dung b\u1eb1ng GZIP khi m\u00e1y kh\u00e1ch h\u1ed7 tr\u1ee3 n\u00f3.<\/p>\n<p>Nh\u01b0 v\u1eady Long V\u00e2n \u0111\u00e3 h\u01b0\u1edbng d\u1eabn Qu\u00fd kh\u00e1ch t\u1ed1i \u01b0u c\u1ea5u h\u00ecnh Apache cho website c\u00f3 l\u01b0u l\u01b0\u1ee3ng cao. Ch\u00fac Qu\u00fd kh\u00e1ch th\u00e0nh c\u00f4ng.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>N\u1ebfu b\u1ea1n \u0111ang ch\u1ea1y m\u1ed9t trang web nh\u1eadn \u0111\u01b0\u1ee3c nhi\u1ec1u l\u01b0u l\u01b0\u1ee3ng truy c\u1eadp, \u0111i\u1ec1u c\u1ea7n thi\u1ebft l\u00e0 ph\u1ea3i t\u1ed1i \u01b0u h\u00f3a c\u1ea5u h\u00ecnh m\u00e1y ch\u1ee7 web Apache c\u1ee7a b\u1ea1n \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o hi\u1ec7u su\u1ea5t v\u00e0 t\u00ednh kh\u1ea3 d\u1ee5ng t\u1ed1i \u0111a. Trong b\u00e0i vi\u1ebft n\u00e0y, Long V\u00e2n s\u1ebd cung c\u1ea5p cho b\u1ea1n m\u1ed9t s\u1ed1 m\u1eb9o [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_oasis_is_in_workflow":0,"_oasis_original":0,"footnotes":""},"categories":[40],"tags":[197,288,289,247,51],"class_list":["post-3979","post","type-post","status-publish","format-standard","hentry","category-web-hosting","tag-apache","tag-apache-mpm","tag-keepalive","tag-toi-uu","tag-web-hosting"],"_links":{"self":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts\/3979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/comments?post=3979"}],"version-history":[{"count":15,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts\/3979\/revisions"}],"predecessor-version":[{"id":4517,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/posts\/3979\/revisions\/4517"}],"wp:attachment":[{"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/media?parent=3979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/categories?post=3979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/longvan.net\/cong-dong\/wp-json\/wp\/v2\/tags?post=3979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}