首页 > 解决方案 > WordPress Firefox 无法在本地主机上建立与服务器的连接

问题描述

我试图在我的本地机器上复制一个 WordPress 站点。我毫无问题地安装了 WordPress,并且基本网站运行良好。我使用Akeeba Kickstarter 导入了我想要的网站,也很顺利。但是现在当我尝试访问 localhost 我得到了错误Firefox can't establish a connection to the server at localhost.

这是我用来安装 WordPress 的演练:https ://ubuntu.com/tutorials/install-and-configure-wordpress#1-overview

Ubuntu、PHP、WordPress 和 MySQL 版本:

在此处输入图像描述

图像中的路径是我的站点所在的位置:/srv/www/wordpress

WordPress 文件夹权限: 在此处输入图像描述

Apache2 状态: 在此处输入图像描述

/srv/www/wordpress/wp-config.php:

<?php

//Begin Really Simple SSL session cookie settings
@ini_set('session.cookie_httponly', true);
@ini_set('session.cookie_secure', true);
@ini_set('session.use_only_cookies', true);
//END Really Simple SSL

//Begin Really Simple SSL Load balancing fix
if ((isset($_ENV["HTTPS"]) && ("on" == $_ENV["HTTPS"]))
|| (isset($_SERVER["HTTP_X_FORWARDED_SSL"]) && (strpos($_SERVER["HTTP_X_FORWARDED_SSL"], "1") !== false))
|| (isset($_SERVER["HTTP_X_FORWARDED_SSL"]) && (strpos($_SERVER["HTTP_X_FORWARDED_SSL"], "on") !== false))
|| (isset($_SERVER["HTTP_CF_VISITOR"]) && (strpos($_SERVER["HTTP_CF_VISITOR"], "https") !== false))
|| (isset($_SERVER["HTTP_CLOUDFRONT_FORWARDED_PROTO"]) && (strpos($_SERVER["HTTP_CLOUDFRONT_FORWARDED_PROTO"], "https") !== false))
|| (isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && (strpos($_SERVER["HTTP_X_FORWARDED_PROTO"], "https") !== false))
|| (isset($_SERVER["HTTP_X_PROTO"]) && (strpos($_SERVER["HTTP_X_PROTO"], "SSL") !== false))
) {
$_SERVER["HTTPS"] = "on";
}
//END Really Simple SSL
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://codex.wordpress.org/Editing_wp-config.php
*
* @package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', 'passwordishere');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', 'keysarehere');
define('SECURE_AUTH_KEY', 'keysarehere');
define('LOGGED_IN_KEY', 'keysarehere');
define('NONCE_KEY', 'keysarehere');
define('AUTH_SALT', 'keysarehere');
define('SECURE_AUTH_SALT', 'keysarehere');
define('LOGGED_IN_SALT', 'keysarehere');
define('NONCE_SALT', 'keysarehere');
/**#@-*/
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the Codex.
*
* @link https://codex.wordpress.org/Debugging_in_WordPress
*/


define('WP_HOME', 'http://localhost');
define('WP_SITEURL', 'http://localhost');


define('WP_DEBUG', false);
define( 'WP_CACHE', true ); // Added by Hummingbird
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

/etc/apache2/sites-available/wordpress.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName wordpress

    DocumentRoot /srv/www/wordpress/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /srv/www/wordpress/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

/srv/www/wordpress/.htaccess

# This file was updated by Duplicator on 2018-07-08 01:00:42. See .htaccess.orig for the original .htaccess file.
# Please note that other plugins and resources write to this file. If the time-stamp above is different
# than the current time-stamp on the file system then another resource has updated this file.
# Duplicator only writes to this file once during the install process while running the installer.php file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
</IfModule>
# END WordPress

/etc/apache2/apache2.conf:

# 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's suggested way to configure the web server. This is because Debian'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
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#Mutex file:${APACHE_LOCK_DIR} default

#
# The directory where shm and other runtime files will be stored.
#

DefaultRuntimeDir ${APACHE_RUN_DIR}

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

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

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


# 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/html>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

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




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

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

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

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

/etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /srv/www/wordpress/

    <Directory /srv/www/wordpress/>
      Options Indexes FollowSymLinks Includes ExecCGI
      AllowOverride All
      Require all granted
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

/var/log/apache2/error.log

[Tue Oct 26 14:09:38.915469 2021] [mpm_prefork:notice] [pid 3822] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:09:38.986332 2021] [mpm_prefork:notice] [pid 4419] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:09:38.986369 2021] [core:notice] [pid 4419] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:12:21.751639 2021] [mpm_prefork:notice] [pid 4419] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:12:21.826730 2021] [mpm_prefork:notice] [pid 4688] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:12:21.826776 2021] [core:notice] [pid 4688] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:18:30.347214 2021] [mpm_prefork:notice] [pid 4688] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:18:30.420845 2021] [mpm_prefork:notice] [pid 4962] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:18:30.420975 2021] [core:notice] [pid 4962] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:28:49.403525 2021] [mpm_prefork:notice] [pid 4962] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:28:49.473800 2021] [mpm_prefork:notice] [pid 5070] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:28:49.473936 2021] [core:notice] [pid 5070] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:47:06.487200 2021] [mpm_prefork:notice] [pid 5070] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:47:06.561239 2021] [mpm_prefork:notice] [pid 5571] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:47:06.561282 2021] [core:notice] [pid 5571] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:47:50.386010 2021] [mpm_prefork:notice] [pid 5571] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:47:50.480106 2021] [mpm_prefork:notice] [pid 5805] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:47:50.480145 2021] [core:notice] [pid 5805] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:49:27.106499 2021] [mpm_prefork:notice] [pid 5805] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:49:27.182037 2021] [mpm_prefork:notice] [pid 6030] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:49:27.182085 2021] [core:notice] [pid 6030] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:49:53.365844 2021] [mpm_prefork:notice] [pid 6030] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:49:53.439728 2021] [mpm_prefork:notice] [pid 6247] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:49:53.439770 2021] [core:notice] [pid 6247] AH00094: Command line: '/usr/sbin/apache2'
[Tue Oct 26 14:57:56.385016 2021] [mpm_prefork:notice] [pid 6247] AH00169: caught SIGTERM, shutting down
[Tue Oct 26 14:57:56.459890 2021] [mpm_prefork:notice] [pid 6304] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 26 14:57:56.459931 2021] [core:notice] [pid 6304] AH00094: Command line: '/usr/sbin/apache2'

/etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

<IfModule ssl_module>
    Listen 443 https
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443 https
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我试过的:

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

对此:

<Directory /srv/www/wordpress/index.php>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

看看我能不能把它强制放到首页。这让我遇到了 403 错误:

在此处输入图像描述

在错误日志 /var/log/apache2/error.log 中有这个:

[Tue Oct 26 15:37:04.226486 2021] [authz_core:error] [pid 6857] [client 127.0.0.1:37076] AH01630: client denied by server configuration: /srv/www/wordpress/
[Tue Oct 26 15:37:04.497433 2021] [authz_core:error] [pid 6857] [client 127.0.0.1:37076] AH01630: client denied by server configuration: /srv/www/wordpress/favicon.ico, referer: http://localhost/

/srv/www/wordpress如上图所示,我更改了目录的权限,但错误没有改变。我是否朝着正确的方向前进?如果我应该包含更多信息,请告诉我。任何帮助表示赞赏,谢谢!

2021 年 10 月 28 日更新

我试过的:

sudo systemctl restart apache2仍然没有运气,每次更改后我都会不断地重新启动 apache2 。Forbidden错误仍然显示。

2021 年 10 月 29 日更新

我试过的:

仍然没有结果。

同一天,另一个更新

我试过的:

在此处输入图像描述

Akeeba 备份再次顺利进行,但我又回到了最初的 Firefox 错误。直到 2021 年 11 月 1 日我才能回复,谢谢您的帮助!

标签: phpwordpressubuntuerror-handlingapache2

解决方案


推荐阅读