如何修复访问WordPress时出现的HTTP 400 Bad Request错误

huangapple go评论75阅读模式
英文:

How to fix HTTP 400 Bad Request error when accessing WordPress

问题

在WordPress站点上,我使用在Google Compute Engine上托管的Apache服务器。我遇到的问题是,当我尝试使用HTTP连接到站点时,出现400 Bad Request错误。HTTPS没有问题,而且我有SSL证书。当Certbot询问我时,我确保将HTTP重定向到HTTPS。

我还在以下文件中进行了必要的更改,但没有进行重定向。如果你有任何线索,我全听着。感谢你的帮助。

这是我的apache2.conf文件:

# 这是主要的Apache服务器配置文件。它包含了
# 给服务器提供指令的配置指令。
# 有关详细信息,请参见http://httpd.apache.org/docs/2.4/
# 以及Debian特定提示的/usr/share/doc/apache2/README.Debian。
#
# ...
#(以下略)

# 全局配置
#

这是我的wordpress-https.conf文件,位于/etc/apache2/sites-enabled

<VirtualHost *:443>
  ServerAdmin admin@example.com
  DocumentRoot /var/www/html
  SSLEngine on

  <Directory /var/www/html>
    Options -Indexes
    AllowOverride FileInfo
  </Directory>
  ServerName enerdf.fr
  Include /etc/letsencrypt/options-ssl-apache.conf
  ServerAlias www.enerdf.fr
  SSLCertificateFile /etc/letsencrypt/live/enerdf.fr/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/enerdf.fr/privkey.pem
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin admin@example.com
  DocumentRoot /var/www/html

  <Directory /var/www/html>
    Options -Indexes
    AllowOverride FileInfo
  </Directory>

  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  RewriteCond %{SERVER_NAME} =enerdf.fr [OR]
  RewriteCond %{SERVER_NAME} =www.enerdf.fr
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

我考虑在每次修改后重新启动服务器,但没有改变任何东西。

英文:

I am on a WordPress site hosted on Google Compute Engine with an Apache server. The problem I am facing is that when I try to connect to my site using HTTP, I get a 400 Bad Request error. There is no problem with HTTPS, and I have an SSL certificate. When Certbot asked me to, I made sure to redirect HTTP to HTTPS.

I have also made the necessary changes in the files below, but no redirection is done.If you have any leads, I am all ears. Thanks for your help.

here my apache2.conf in etc/apache2/

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream&#39;s suggested way to configure the web server. This is because Debian&#39;s
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#       /etc/apache2/
#       |-- apache2.conf
#       |       `--  ports.conf
#       |-- mods-enabled
#       |       |-- *.load
#       |       `-- *.conf
#       |-- conf-enabled
#       |       `-- *.conf
#       |       `-- sites-enabled
#       |       `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

<!-- end snippet -->

here my conf enabled "wordpress-https.conf" in /etc/apache2/sites-enabled

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;VirtualHost *:443&gt;
  ServerAdmin admin@example.com
  DocumentRoot /var/www/html
  SSLEngine on

  &lt;Directory /var/www/html&gt;
    Options -Indexes
    AllowOverride FileInfo
  &lt;/Directory&gt;
    ServerName enerdf.fr
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias www.enerdf.fr
SSLCertificateFile /etc/letsencrypt/live/enerdf.fr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/enerdf.fr/privkey.pem
&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
  ServerAdmin admin@example.com
  DocumentRoot /var/www/html

  &lt;Directory /var/www/html&gt;
    Options -Indexes
    AllowOverride FileInfo
  &lt;/Directory&gt;

  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{SERVER_NAME} =enerdf.fr [OR]
RewriteCond %{SERVER_NAME} =www.enerdf.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
&lt;/VirtualHost&gt;

<!-- end snippet -->

I thought about restarting the server after each modification, but it doesn't change anything

答案1

得分: 1

我最终发现我需要像这样在端口80上禁用SSL:

<!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->

<!-- 语言:lang-html -->
<VirtualHost *:80>
  ServerName exemple.com
  SSLEngine off
  Redirect permanent / https://exemple.com
</VirtualHost>

<!-- 结束代码片段 -->
英文:

I finally found that I needed to disable ssl on port 80 like this :

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;VirtualHost *:80&gt;
  ServerName exemple.com
  SSLEngine off
  Redirect permanent / https://exemple.com
&lt;/VirtualHost&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月3日 20:53:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定