![为 mediawiki 配置 apache2](https://linux22.com/image/1055988/%E4%B8%BA%20mediawiki%20%E9%85%8D%E7%BD%AE%20apache2.png)
为了使 mediawiki 在 apache2 上运行,/etc/apache2/conf/mediawiki
需要一个文件。我在哪里可以找到它?
答案1
一个好主意是为您服务器上的每个 MediaWiki 创建一个专用的虚拟主机(将运行单独的子域)。Apache2虚拟主机配置文件文件包含在文件夹中/etc/apache2/sites-available/
。
例如,VH 配置文件可以这样命名(注意其名称必须以 结尾.conf
):。其示例内容应类似于:/etc/apache2/sites-available/wiki.example.com.conf
<VirtualHost *:80>
ServerName wiki.example.com
ServerAdmin [email protected]
# Redirect Requests to SSL
Redirect permanent "/" "https://wiki.example.com/"
ErrorLog ${APACHE_LOG_DIR}/wiki.example.com.error.log
CustomLog ${APACHE_LOG_DIR}/wiki.example.com.access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName wiki.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/wiki.example.com
# According MWiki Manual:Security
php_flag register_globals off
ErrorLog ${APACHE_LOG_DIR}/wiki.example.com.error.log
CustomLog ${APACHE_LOG_DIR}/wiki.example.com.access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/wiki.example.com.crt
SSLCertificateKeyFile /etc/ssl/private/wiki.example.com.key
SSLCertificateChainFile /etc/ssl/certs/wiki.example.com.root-bundle.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory /var/www/wiki.example.com>
Options None FollowSymLinks
#Allow .htaccess
AllowOverride All
Require all granted
<IfModule security2_module>
SecRuleEngine Off
# or disable only problematic rules
</IfModule>
</Directory>
# According to MWiki Manual:Security
<Directory /var/www/wiki.example.com/images>
# Ignore .htaccess files
AllowOverride None
# Serve HTML as plaintext, don't execute SHTML
AddType text/plain .html .htm .shtml .php .phtml .php5
# Don't run arbitrary PHP code.
php_admin_flag engine off
# If you've other scripting languages, disable them too.
</Directory>
#According to MWiki Manual:Security
<Directory /var/www/wiki.example.com/images/deleted>
Deny from all
AllowOverride AuthConfig Limit
Require local
</Directory>
</VirtualHost>
</IfModule>
请注意,此示例适用于启用 HTTPS/SSL 的配置。对于纯 HTTP,它必须如下所示:
<VirtualHost *:80>
ServerName wiki.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/wiki.example.com
# According MWiki Manual:Security
php_flag register_globals off
ErrorLog ${APACHE_LOG_DIR}/wiki.example.com.error.log
CustomLog ${APACHE_LOG_DIR}/wiki.example.com.access.log combined
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory /var/www/wiki.example.com>
Options None FollowSymLinks
#Allow .htaccess
AllowOverride All
Require all granted
<IfModule security2_module>
SecRuleEngine Off
# or disable only problematic rules
</IfModule>
</Directory>
# According to MWiki Manual:Security
<Directory /var/www/wiki.example.com/images>
# Ignore .htaccess files
AllowOverride None
# Serve HTML as plaintext, don't execute SHTML
AddType text/plain .html .htm .shtml .php .phtml .php5
# Don't run arbitrary PHP code.
php_admin_flag engine off
# If you've other scripting languages, disable them too.
</Directory>
#According to MWiki Manual:Security
<Directory /var/www/wiki.example.com/images/deleted>
Deny from all
AllowOverride AuthConfig Limit
Require local
</Directory>
</VirtualHost>
要激活 VirtyalHost,您需要运行:
sudo a2ensite wiki.example.com.conf
sudo systemctl restart apache2.service
另请阅读: