{"id":1183,"date":"2025-10-11T17:17:45","date_gmt":"2025-10-11T09:17:45","guid":{"rendered":"https:\/\/www.chinaenow.com\/blog\/?p=1183"},"modified":"2025-10-11T17:17:45","modified_gmt":"2025-10-11T09:17:45","slug":"portal%e8%ae%a4%e8%af%81%e5%9c%a8%e5%93%aa%e9%87%8c%e9%85%8d%e7%bd%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.chinaenow.com\/blog\/1183.html","title":{"rendered":"Portal\u8ba4\u8bc1\u5728\u54ea\u91cc\u914d\u7f6e\uff1f"},"content":{"rendered":"<p><p>\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u914d\u7f6e\u548c\u5b9e\u73b0Portal\u8ba4\u8bc1\uff0c\u89e3\u51b3\u7528\u6237\u767b\u5f55\u9a8c\u8bc1\u7684\u95ee\u9898\u3002\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\uff0c\u60a8\u5c06\u5b66\u4f1a\u5982\u4f55\u8bbe\u7f6e\u7528\u6237\u8ba4\u8bc1\u8fc7\u7a0b\uff0c\u5e76\u786e\u4fdd\u7cfb\u7edf\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.chinaenow.com\/blog\/wp-content\/uploads\/2025\/10\/64264NClKB.jpg\" alt=\"Portal\u8ba4\u8bc1\u5728\u54ea\u91cc\u914d\u7f6e\uff1f\" title=\"Portal\u8ba4\u8bc1\u5728\u54ea\u91cc\u914d\u7f6e\uff1f\"><\/p>\n<\/p>\n<p><h2>1. \u64cd\u4f5c\u524d\u7684\u51c6\u5907\u6216\u80cc\u666f\u4ecb\u7ecd<\/h2>\n<\/p>\n<p><p>\u5728\u8fdb\u884cPortal\u8ba4\u8bc1\u914d\u7f6e\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u7684Linux\u670d\u52a1\u5668\u5df2\u7ecf\u5b89\u88c5\u4e86Apache\u670d\u52a1\u5668\u548cApache\u7684mod_auth_mysql\u6a21\u5757\u3002\u8fd9\u4e9b\u662f\u5b9e\u73b0\u7528\u6237\u8ba4\u8bc1\u7684\u57fa\u7840\u7ec4\u4ef6\u3002<\/p>\n<\/p>\n<p><h2>2. \u5b8c\u6210\u4efb\u52a1\u6240\u9700\u7684\u8be6\u7ec6\u3001\u5206\u6b65\u64cd\u4f5c\u6307\u5357<\/h2>\n<\/p>\n<p><h3>2.1 \u5b89\u88c5Apache\u548cmod_auth_mysql<\/h3>\n<\/p>\n<p><p>\u5728\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5Apache\u548cmod_auth_mysql\u3002<\/p>\n<\/p>\n<p><pre><code>sudo apt-get update<\/p>\r\n<p>sudo apt-get install apache2 libapache2-mod-auth-mysql<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.2 \u914d\u7f6eMySQL\u6570\u636e\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u7528\u4e8e\u5b58\u50a8\u7528\u6237\u4fe1\u606f\u3002<\/p>\n<\/p>\n<ul>\n<li>\u767b\u5f55MySQL\u6570\u636e\u5e93<\/li>\n<li>\u521b\u5efa\u6570\u636e\u5e93\u548c\u7528\u6237\u8868<\/li>\n<li>\u8bbe\u7f6e\u7528\u6237\u6743\u9650<\/li>\n<\/ul>\n<p><pre><code>mysql -u root -p<\/p>\r\n<p>CREATE DATABASE portal_auth;<\/p>\r\n<p>USE portal_auth;<\/p>\r\n<p>CREATE TABLE users (<\/p>\r\n<p>    id INT NOT NULL AUTO_INCREMENT,<\/p>\r\n<p>    username VARCHAR(50) NOT NULL,<\/p>\r\n<p>    password VARCHAR(50) NOT NULL,<\/p>\r\n<p>    PRIMARY KEY (id)<\/p>\r\n<p>);<\/p>\r\n<p>GRANT ALL PRIVILEGES ON portal_auth. TO 'auth_user'@'localhost' IDENTIFIED BY 'your_password';<\/p>\r\n<p>FLUSH PRIVILEGES;<\/p>\r\n<p>EXIT;<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.3 \u914d\u7f6eApache\u670d\u52a1\u5668<\/h3>\n<\/p>\n<p><p>\u7f16\u8f91Apache\u7684\u914d\u7f6e\u6587\u4ef6\u4ee5\u542f\u7528mod_auth_mysql\u6a21\u5757\uff0c\u5e76\u8bbe\u7f6e\u8ba4\u8bc1\u3002<\/p>\n<\/p>\n<p><pre><code>sudo nano \/etc\/apache2\/apache2.conf<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\u6765\u542f\u7528mod_auth_mysql\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code>LoadModule auth_mysql_module modules\/mod_auth_mysql.so<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.4 \u914d\u7f6e\u8ba4\u8bc1\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u8ba4\u8bc1\u6587\u4ef6\uff0c\u4f8b\u5982<code>portal_auth.conf<\/code>\uff0c\u5e76\u8bbe\u7f6e\u8ba4\u8bc1\u89c4\u5219\u3002<\/p>\n<\/p>\n<p><pre><code>sudo nano \/etc\/apache2\/sites-available\/portal_auth.conf<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code>&lt;VirtualHost :80&gt;<\/p>\r\n<p>    ServerAdmin webmaster@localhost<\/p>\r\n<p>    ServerName localhost<\/p>\r\n<p>    DocumentRoot \/var\/www\/html<\/p>\r\n<p>    ErrorLog ${APACHE_LOG_DIR}\/error.log<\/p>\r\n<p>    CustomLog ${APACHE_LOG_DIR}\/access.log combined<\/p>\r\n\r\n<p>    &lt;Directory \/var\/www\/html&gt;<\/p>\r\n<p>        Options Indexes FollowSymLinks<\/p>\r\n<p>        AllowOverride None<\/p>\r\n<p>        Require all granted<\/p>\r\n<p>        AuthType MySQL<\/p>\r\n<p>        AuthMySQLUser auth_user<\/p>\r\n<p>        AuthMySQLPassword your_password<\/p>\r\n<p>        AuthMySQLDatabase portal_auth<\/p>\r\n<p>        AuthMySQLHost localhost<\/p>\r\n<p>        AuthMySQLSelectField password<\/p>\r\n<p>        AuthMySQLSelectUserField username<\/p>\r\n<p>        AuthMySQLTableName users<\/p>\r\n<p>        AuthMySQLCheckUser off<\/p>\r\n<p>        AuthMySQLDBDType MYSQL<\/p>\r\n<p>        AuthMySQLConnectionTimeout 10<\/p>\r\n<p>        AuthMySQLSocket \/var\/run\/mysqld\/mysqld.sock<\/p>\r\n<p>        AuthName \"Portal Authentication\"<\/p>\r\n<p>        Require valid-user<\/p>\r\n<p>    &lt;\/Directory&gt;<\/p>\r\n<p>&lt;\/VirtualHost&gt;<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.5 \u542f\u7528\u65b0\u914d\u7f6e\u5e76\u91cd\u542fApache<\/h3>\n<\/p>\n<p><p>\u542f\u7528\u65b0\u914d\u7f6e\u5e76\u91cd\u542fApache\u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/p>\n<\/p>\n<p><pre><code>sudo a2ensite portal_auth.conf<\/p>\r\n<p>sudo a2dissite 000-default.conf<\/p>\r\n<p>sudo a2enmod auth_mysql<\/p>\r\n<p>sudo systemctl restart apache2<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3. \u6d89\u53ca\u7684\u5173\u952e\u547d\u4ee4\u3001\u4ee3\u7801\u6216\u914d\u7f6e\u793a\u4f8b<\/h2>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u5173\u952e\u547d\u4ee4\u548c\u914d\u7f6e\u7684\u603b\u7ed3\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5Apache\u548cmod_auth_mysql\uff1a<\/p>\n<p><pre><code>sudo apt-get install apache2 libapache2-mod-auth-mysql<\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u521b\u5efa\u6570\u636e\u5e93\u548c\u7528\u6237\u8868\uff1a<\/p>\n<p><pre><code>CREATE DATABASE portal_auth;<\/p>\r\n<p>CREATE TABLE users (<\/p>\r\n<p>    id INT NOT NULL AUTO_INCREMENT,<\/p>\r\n<p>    username VARCHAR(50) NOT NULL,<\/p>\r\n<p>    password VARCHAR(50) NOT NULL,<\/p>\r\n<p>    PRIMARY KEY (id)<\/p>\r\n<p>);<\/code><\/pre>\n<\/p>\n<\/li>\n<li>\u914d\u7f6eApache\u8ba4\u8bc1\uff1a<\/p>\n<p><pre><code>AuthType MySQL<\/p>\r\n<p>AuthMySQLUser auth_user<\/p>\r\n<p>AuthMySQLPassword your_password<\/p>\r\n<p>AuthMySQLDatabase portal_auth<\/p>\r\n<p>...<\/code><\/pre>\n<\/p>\n<\/ul>\n<p><h2>4. \u5bf9\u547d\u4ee4\u3001\u4ee3\u7801\u6216\u91cd\u8981\u6982\u5ff5\u7684\u6e05\u6670\u89e3\u91ca<\/h2>\n<\/p>\n<p><p><strong>AuthType MySQL<\/strong> \u6307\u5b9a\u8ba4\u8bc1\u7c7b\u578b\u4e3aMySQL\u3002<\/p>\n<p><code>AuthMySQLUser<\/code> \u548c <code>AuthMySQLPassword<\/code> \u662f\u7528\u4e8e\u8fde\u63a5MySQL\u6570\u636e\u5e93\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/p>\n<p><code>AuthMySQLDatabase<\/code> \u662f\u5b58\u50a8\u7528\u6237\u4fe1\u606f\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><h2>5. \u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u3001\u6ce8\u610f\u4e8b\u9879\u6216\u76f8\u5173\u7684\u5b9e\u7528\u6280\u5de7<\/h2>\n<\/p>\n<ul>\n<li><strong>\u95ee\u9898\uff1a<\/strong>\u8ba4\u8bc1\u5931\u8d25\u3002<\/p>\n<li><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u68c0\u67e5\u6570\u636e\u5e93\u8fde\u63a5\u8bbe\u7f6e\u662f\u5426\u6b63\u786e\uff0c\u4ee5\u53ca\u7528\u6237\u540d\u548c\u5bc6\u7801\u662f\u5426\u6b63\u786e\u3002<\/li>\n<\/li>\n<li><strong>\u95ee\u9898\uff1a<\/strong>Apache\u65e0\u6cd5\u627e\u5230\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<li><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u786e\u4fdd\u914d\u7f6e\u6587\u4ef6\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u6587\u4ef6\u5177\u6709\u6b63\u786e\u7684\u6743\u9650\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Linux\u7cfb\u7edf\u4e2d\u914d\u7f6e\u548c\u5b9e\u73b0Portal\u8ba4\u8bc1\uff0c\u89e3\u51b3\u7528\u6237\u767b\u5f55\u9a8c\u8bc1\u7684\u95ee\u9898\u3002\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\uff0c\u60a8\u5c06\u5b66\u4f1a\u5982\u4f55\u8bbe\u7f6e\u7528\u6237\u8ba4\u8bc1\u8fc7\u7a0b\uff0c\u5e76\u786e\u4fdd\u7cfb\u7edf\u7684\u5b89\u5168\u6027\u3002 1. \u64cd\u4f5c\u524d\u7684\u51c6\u5907\u6216\u80cc\u666f\u4ecb\u7ecd \u5728\u8fdb\u884cPortal\u8ba4\u8bc1\u914d\u7f6e\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u7684Linux\u670d\u52a1&#8230;<\/p>\n","protected":false},"author":2,"featured_media":1184,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[179,254,253],"topic":[],"class_list":["post-1183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-usdt","tag-apache","tag-portal","tag-253"],"_links":{"self":[{"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/posts\/1183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/comments?post=1183"}],"version-history":[{"count":1,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/posts\/1183\/revisions"}],"predecessor-version":[{"id":1186,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/posts\/1183\/revisions\/1186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/media\/1184"}],"wp:attachment":[{"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/media?parent=1183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/categories?post=1183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/tags?post=1183"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.chinaenow.com\/blog\/wp-json\/wp\/v2\/topic?post=1183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}