{"id":138,"date":"2025-10-30T21:44:52","date_gmt":"2025-10-30T13:44:52","guid":{"rendered":"https:\/\/luckyfish.app\/?p=138"},"modified":"2025-10-31T16:56:10","modified_gmt":"2025-10-31T08:56:10","slug":"vite-react-project-%e4%bb%a5-apache2-service-%e5%b0%8e%e5%87%ba","status":"publish","type":"post","link":"https:\/\/blog.luckyfish.app\/?p=138","title":{"rendered":"Vite\/React project \u4ee5 Apache2 Service \u5c0e\u51fa"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-392f4849782d82649e04dfa4e119435d\" style=\"color:#555555\">\u6709\u4e9b\u4eba\u53ef\u80fd\u4e0d\u662f\u4f7f\u7528 LAMP\uff0c\u53ef\u80fd\u662f\u4f7f\u7528 node.js \u67b6\u8a2d\u7db2\u7ad9\uff0c\u9019\u908a\u5c31\u4ee5 vite + react \u4ee5 Apache2 Service \u5c0e\u51fa\u3002\u4e3b\u8981\u662f\u900f\u904e\u5c07\u524d\u7aef build \u6210\u975c\u614b\u9801\u9762\u518d\u7531 Apache2  Server \u4ee3\u7406\u3002<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-f9a06962630e1bec5f104bbcf3fac813\" style=\"color:#555555\">\u5148\u5728\u5c08\u6848\u57f7\u884c\uff0c\u57f7\u884c\u5b8c\u6210\u5f8c\u6703\u5728\u8a72\u5c08\u6848\u5e95\u4e0b\u7522\u51fa\u4e00\u500b dist \u6a94\u6848\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-text-color has-background has-link-color wp-elements-fc94d1602baae525891992d3b3e89e89\" style=\"background-color:#555555\"><code>sudo npm run build<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-f91810b981cb75ef17219fe09d5da557\" style=\"color:#555555\">\u63a5\u4e0b\u4f86\u5fc5\u9808\u8a18\u5f97\u66f4\u6539 owner\uff01\u6211\u7684\u5c08\u6848\u8def\u5f91\u70ba \/var\/www\/wxyz\/<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-text-color has-background has-link-color wp-elements-407ada27039000c72c99380b5afa54f2\" style=\"background-color:#555555\"><code>sudo chown -R www-data:www-data \/var\/www\/wxyz\/<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-d13f2f43fea989d7564bf98b05f04ffe\" style=\"color:#555555\">\u518d\u4f86\u5c31\u662f Apache2 \u8a2d\u5b9a\u6a94\u7684\u90e8\u5206\u4e86<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-386166ce15658db1c703593e47625e58\" style=\"color:#555555\">\u9996\u5148\u65b0\u589e\u4e00\u500b\u8a2d\u5b9a\u6a94\uff0c\u9019\u908a\u4ee5 wxyz \u70ba\u5b50\u57df\u540d\u70ba\u793a\u7bc4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-text-color has-background has-link-color wp-elements-800f00699394906791d31805d28f19a5\" style=\"background-color:#555555\"><code>\/etc\/apache2\/sites-available\/wxyz.conf<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-ee83b821a4cf1760b269602d028e09b0\" style=\"color:#555555\">\u5167\u5bb9\u518d\u91dd\u5c0d\u5b50\u57df\u540d\u505a\u4fee\u6539\u5373\u53ef\uff0cDocumentRoot \u53ca Directory \u4f4d\u7f6e\u5fc5\u9808\u586b\u5beb\u6b63\u78ba\u5230 dist \u6a94\u6848\u8def\u5f91\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-text-color has-background has-link-color wp-elements-3a069a35982cb31336e2889b7682b9e6\" style=\"background-color:#555555\"><code># 80 -> \u4e00\u5f8b\u5c0e\u5230 HTTPS\n&lt;VirtualHost *:80>\n    ServerName wxyz.luckyfish.app\n    Redirect permanent \/ https:\/\/wxyz.luckyfish.app\/\n&lt;\/VirtualHost>\n\n# 443 \u6b63\u7ad9\n&lt;VirtualHost *:443>\n  ServerName wxyz.luckyfish.app\n  DocumentRoot \/var\/www\/wxyz\/frontend\/dist\n \n  SSLEngine on\n  SSLCertificateFile \/etc\/apache2\/ssl\/public.pem\n  SSLCertificateKeyFile \/etc\/apache2\/ssl\/private.key\n  Protocols h2 http\/1.1\n\n  &lt;Directory \/var\/www\/wxyz\/frontend\/dist>\n    AllowOverride all\n    Require all granted\n  &lt;\/Directory>\n\n  ErrorLog  ${APACHE_LOG_DIR}\/dev_error.log\n  CustomLog ${APACHE_LOG_DIR}\/dev_access.log combined\n&lt;\/VirtualHost>\n\nRedirectMatch 404 \/\\\\.(svn|git|hg|bzr|cvs)(\/|$)<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-d9789716aa30600b96453516f6257eab\" style=\"color:#555555\">\u6700\u5f8c\u8981\u555f\u7528\u525b\u525b\u6240\u8a2d\u5b9a\u7684 profile \u8a2d\u5b9a\u6a94\uff0c\u4e00\u6a23\u6839\u64da\u6a94\u540d\u53bb\u555f\u52d5\uff0c\u5c31\u6210\u529f\u4e86\uff01<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-text-color has-background has-link-color wp-elements-023af46d8d71681f5dffc08ffe72fc8e\" style=\"background-color:#555555\"><code>sudo a2ensite wxyz\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-e6166d92d4c03f08ffdfe90e32436f12\" style=\"color:#555555\">\u6700\u5f8c\u8981\u8a18\u5f97\u6bcf\u6b21\u6709\u57f7\u884c sudo npm run build\uff0c\u90fd\u8981\u8a18\u5f97\u505a chown\uff01\u907f\u514d\u53ef\u80fd\u51fa\u73fe\u6b0a\u9650\u554f\u984c\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e9b\u4eba\u53ef\u80fd\u4e0d\u662f\u4f7f\u7528 LAMP\uff0c\u53ef\u80fd\u662f\u4f7f\u7528 node.js \u67b6\u8a2d\u7db2\u7ad9\uff0c\u9019\u908a\u5c31\u4ee5 vite + react \u4ee5 A [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,3],"tags":[6],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-linux","category-3","tag-6"],"_links":{"self":[{"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":10,"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions\/165"}],"wp:attachment":[{"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.luckyfish.app\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}