前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WordPress - Apache2 配置文件和开启重写模式

WordPress - Apache2 配置文件和开启重写模式

作者头像
AIHGF
发布2019-02-27 17:39:44
1K0
发布2019-02-27 17:39:44
举报
文章被收录于专栏:AIUAIAIUAIAIUAI

WordPress - Apache2 配置文件和开启重写模式

在开始尝试 WordPrss 时, 访问博客文章会出现错误:

The requested URL /hello-world-.html was not found on this server 

查找各种答案, 发现是由 Apache2 未开启重写模式 导致的.

关于重写模式, 很多资源都是介绍修改 Apache2 httpd.conf, 但我找了很久都未找到 httpd.conf 文件.

Ubuntu 终端查找命令:

find / -name httpd.conf

实际上, Apache2 并没有 httpd.conf 配置文件, 真实的Apache2配置文件是 /etc/apache2/apache2.conf. Apache2 启动时默认自动读取该文件内的配置信息, 而其它的配置信息则是通过 Include 包含进来的. 如:

# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf

# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/*.conf

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include list of ports to listen on
Include ports.conf

1. Apache2 配置文件

/etc/apache2/ 的目录结构:

python ├── apache2.conf # 配置文件 ├── ports.conf ├── conf-available └── *.conf ├── conf-enabled └── *.conf ├── mods-available ├── *.load └── *.conf ├── mods-enabled ├── *.load └── *.conf ├── sites-available ├── 000-default.conf └── default-ssl.conf ├── sites-enabled └── 000-default.conf

available 和 enabled 文件夹的区别和作用: - enable/ 文件夹内的文件, 是被包含在 apache2.conf 内的配置, 即生效的配置文件. - available/ 文件夹内的文件, 是未用到所有可能用到的配置文件, 即未生效的配置文件. 如果需要特定设置, 即从 available 文件夹内复制对应的配置文件到 enabled 文件夹内, 即可.

2. Apache2 开启重写模式

LoadModule rewrite_module

  • 复制 rewrite.load 文件到 mods-enabled 文件夹:
sudo cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
  • 更改 mods-enabled/rewrite.load 文件权限:
chmod -R 775 rewrite.load
  • 编辑 apache2.conf 配置参数:
sudo vim apache2.conf
  • 更改如下部分的参数: 更改前: AllowOverride None 更改后:AllowOverride All

更改前:

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>

更改后:

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride All
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>
  • 重启 Apache
sudo systemctl restart apache2.service
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年05月17日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • WordPress - Apache2 配置文件和开启重写模式
    • 1. Apache2 配置文件
      • 2. Apache2 开启重写模式
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档