問題描述
我正在關注 This tutorial 創建一個 WordPress 網站的網絡。加入後
/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );
到我的 wp-config.php 文件,當我開始配置多站點網絡我得到這個錯誤
ERROR: You cannot install a network of sites with your server address.
You cannot use port numbers such as :8080
我試着改變
Listen 0.0.0.0:8080
Listen [::0]:8080
至
Listen 0.0.0.0:80
Listen [::0]:80
從 Apache 的 httpd.conf,但由於這個 wamp 服務器仍然是橙色。如何解決這個問題我是 WordPress 的新手任何幫助將非常感謝。
最佳解決方案
警告:這只是開發人員安裝而不是生產站點的測試
我很好奇,看看是否有解決方法,對於那些想要在開發人員安裝而不是:80 和:443 的不同端口開發多功能的用户。 :8080 。
我只發現了 Henri Benoit 的這個 blog post 。在那裏他給出瞭如何修改 3.9.1 核心的例子,以擺脱核心的限制。
這是一個 must-use 插件/wp-content/mu-plugins/wpse-ms-on-different-port.php,我們試圖避免核心修改:
<?php
/**
* Test for multisite support on a different port than :80 and :443 (e.g. :8080)
*
* Here we assume that the 'siteurl' and 'home' options contain the :8080 port
*
* WARNING: Not suited for production sites!
*/
/**
* Get around the problem with wpmu_create_blog() where sanitize_user()
* strips out the semicolon (:) in the $domain string
* This means created sites with hostnames of
* e.g. example.tld8080 instead of example.tld:8080
*/
add_filter( 'sanitize_user', function( $username, $raw_username, $strict )
{
// Edit the port to your needs
$port = 8080;
if( $strict // wpmu_create_blog uses strict mode
&& is_multisite() // multisite check
&& $port == parse_url( $raw_username, PHP_URL_PORT ) // raw domain has port
&& false === strpos( $username, ':' . $port ) // stripped domain is without correct port
)
$username = str_replace( $port, ':' . $port, $username ); // replace e.g. example.tld8080 to example.tld:8080
return $username;
}, 1, 3 );
/**
* Temporarly change the port (e.g. :8080 ) to :80 to get around
* the core restriction in the network.php page.
*/
add_action( 'load-network.php', function()
{
add_filter( 'option_active_plugins', function( $value )
{
add_filter( 'option_siteurl', function( $value )
{
// Edit the port to your needs
$port = 8080;
// Network step 2
if( is_multisite() || network_domain_check() )
return $value;
// Network step 1
static $count = 0;
if( 0 === $count++ )
$value = str_replace( ':' . $port, ':80', $value );
return $value;
} );
return $value;
} );
} );
我剛剛在我的開發工具上進行了測試,但這可能需要更多的檢查;-)
次佳解決方案
您不能使用端口 8080. 我不知道為什麼這是一個相當常見的 Web 服務器端口。但是,you can’t:
121 if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
122 echo '<div class="error"><p><strong>' . __( 'ERROR:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
123 echo '<p>' . sprintf(
124 /* translators: %s: port number */
125 __( 'You cannot use port numbers such as %s.' ),
126 '<code>' . $has_ports . '</code>'
127 ) . '</p>';
128 echo '<a href="http://'%20.%20esc_url(%20admin_url()%20)%20.%20'">' . __( 'Return to Dashboard' ) . '</a>';
129 echo '</div>';
130 include( ABSPATH . 'wp-admin/admin-footer.php' );
131 die();
132 }
注意! in_array( $has_ports, array( ':80', ':443' ) )。那些端口是 hard-coded 。沒有可以用來改變它們的過濾器,甚至不能在 get_clean_basename()中使用 (如果你能改變返回的結果,我恐怕會猜到你會創造什麼恐怖) 。
更改您的服務器以使用端口 443 或端口 80 。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。