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

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

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文件:

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

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

  1. <VirtualHost *:443>
  2. ServerAdmin admin@example.com
  3. DocumentRoot /var/www/html
  4. SSLEngine on
  5. <Directory /var/www/html>
  6. Options -Indexes
  7. AllowOverride FileInfo
  8. </Directory>
  9. ServerName enerdf.fr
  10. Include /etc/letsencrypt/options-ssl-apache.conf
  11. ServerAlias www.enerdf.fr
  12. SSLCertificateFile /etc/letsencrypt/live/enerdf.fr/fullchain.pem
  13. SSLCertificateKeyFile /etc/letsencrypt/live/enerdf.fr/privkey.pem
  14. </VirtualHost>
  15. <VirtualHost *:80>
  16. ServerAdmin admin@example.com
  17. DocumentRoot /var/www/html
  18. <Directory /var/www/html>
  19. Options -Indexes
  20. AllowOverride FileInfo
  21. </Directory>
  22. RewriteEngine On
  23. RewriteCond %{HTTPS} off
  24. RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  25. RewriteCond %{SERVER_NAME} =enerdf.fr [OR]
  26. RewriteCond %{SERVER_NAME} =www.enerdf.fr
  27. RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
  28. </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 -->

  1. # This is the main Apache server configuration file. It contains the
  2. # configuration directives that give the server its instructions.
  3. # See http://httpd.apache.org/docs/2.4/ for detailed information about
  4. # the directives and /usr/share/doc/apache2/README.Debian about Debian specific
  5. # hints.
  6. #
  7. #
  8. # Summary of how the Apache 2 configuration works in Debian:
  9. # The Apache 2 web server configuration in Debian is quite different to
  10. # upstream&#39;s suggested way to configure the web server. This is because Debian&#39;s
  11. # default Apache2 installation attempts to make adding and removing modules,
  12. # virtual hosts, and extra configuration directives as flexible as possible, in
  13. # order to make automating the changes and administering the server as easy as
  14. # possible.
  15. # It is split into several files forming the configuration hierarchy outlined
  16. # below, all located in the /etc/apache2/ directory:
  17. #
  18. # /etc/apache2/
  19. # |-- apache2.conf
  20. # | `-- ports.conf
  21. # |-- mods-enabled
  22. # | |-- *.load
  23. # | `-- *.conf
  24. # |-- conf-enabled
  25. # | `-- *.conf
  26. # | `-- sites-enabled
  27. # | `-- *.conf
  28. #
  29. #
  30. # * apache2.conf is the main configuration file (this file). It puts the pieces
  31. # together by including all remaining configuration files when starting up the
  32. # web server.
  33. #
  34. # * ports.conf is always included from the main configuration file. It is
  35. # supposed to determine listening ports for incoming connections which can be
  36. # customized anytime.
  37. #
  38. # * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
  39. # directories contain particular configuration snippets which manage modules,
  40. # global configuration fragments, or virtual host configurations,
  41. # respectively.
  42. #
  43. # They are activated by symlinking available configuration files from their
  44. # respective *-available/ counterparts. These should be managed by using our
  45. # helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
  46. # their respective man pages for detailed information.
  47. #
  48. # * The binary is called apache2. Due to the use of environment variables, in
  49. # the default configuration, apache2 needs to be started/stopped with
  50. # /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
  51. # work with the default configuration.
  52. # Global configuration
  53. #

<!-- 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 -->

  1. &lt;VirtualHost *:443&gt;
  2. ServerAdmin admin@example.com
  3. DocumentRoot /var/www/html
  4. SSLEngine on
  5. &lt;Directory /var/www/html&gt;
  6. Options -Indexes
  7. AllowOverride FileInfo
  8. &lt;/Directory&gt;
  9. ServerName enerdf.fr
  10. Include /etc/letsencrypt/options-ssl-apache.conf
  11. ServerAlias www.enerdf.fr
  12. SSLCertificateFile /etc/letsencrypt/live/enerdf.fr/fullchain.pem
  13. SSLCertificateKeyFile /etc/letsencrypt/live/enerdf.fr/privkey.pem
  14. &lt;/VirtualHost&gt;
  15. &lt;VirtualHost *:80&gt;
  16. ServerAdmin admin@example.com
  17. DocumentRoot /var/www/html
  18. &lt;Directory /var/www/html&gt;
  19. Options -Indexes
  20. AllowOverride FileInfo
  21. &lt;/Directory&gt;
  22. RewriteEngine On
  23. RewriteCond %{HTTPS} off
  24. RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  25. RewriteCond %{SERVER_NAME} =enerdf.fr [OR]
  26. RewriteCond %{SERVER_NAME} =www.enerdf.fr
  27. RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
  28. &lt;/VirtualHost&gt;

<!-- end snippet -->

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

答案1

得分: 1

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

  1. <!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->
  2. <!-- 语言:lang-html -->
  3. <VirtualHost *:80>
  4. ServerName exemple.com
  5. SSLEngine off
  6. Redirect permanent / https://exemple.com
  7. </VirtualHost>
  8. <!-- 结束代码片段 -->
英文:

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 -->

  1. &lt;VirtualHost *:80&gt;
  2. ServerName exemple.com
  3. SSLEngine off
  4. Redirect permanent / https://exemple.com
  5. &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:

确定