VPS 上的第二个虚拟主机显示“无法连接到服务器”

VPS 上的第二个虚拟主机显示“无法连接到服务器”

我使用的是 Debian 7 Wheezy 和 Apache 2.2.22,并且正在 VPS 上为多个网站设置虚拟主机。我已成功为其中一个网站配置 VirtualHost 指令,但第二个网站在 Firefox 中不断显示“加载页面时出现问题”。我已运行并验证了我的所有语法均正确无误,并且我已检查了所有权限。第二个域上的所有内容几乎都是从第一个域复制/粘贴的,因此我不确定问题是什么,因为除了我重新加载配置的位置之外,configtest没有其他条目:/var/log/apache2/error.log

/# cat /var/log/apache2/error.log
[Thu May 29 01:19:00 2014] [notice] Graceful restart requested, doing restart
[Thu May 29 01:19:00 2014] [info] Init: Seeding PRNG with 656 bytes of entropy
[Thu May 29 01:19:00 2014] [info] Init: Generating temporary RSA private keys (512/1024 bits)
[Thu May 29 01:19:00 2014] [info] Init: Generating temporary DH parameters (512/1024 bits)
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(253): shmcb_init allocated 512000 bytes of shared memory
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(272): for 511920 bytes (512000 including header), recommending 32 subcaches, 133 indexes each
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(306): shmcb_init_memory choices follow
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(308): subcache_num = 32
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(310): subcache_size = 15992
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(312): subcache_data_offset = 3208
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(314): subcache_data_size = 12784
[Thu May 29 01:19:00 2014] [debug] ssl_scache_shmcb.c(316): index_num = 133
[Thu May 29 01:19:00 2014] [info] Shared memory session cache initialised
[Thu May 29 01:19:00 2014] [info] Init: Initializing (virtual) servers for SSL
[Thu May 29 01:19:00 2014] [info] mod_ssl/2.2.22 compiled against Server: Apache/2.2.22, Library: OpenSSL/1.0.1e
[Thu May 29 01:19:00 2014] [notice] Apache/2.2.22 (Debian) PHP/5.4.4-14+deb7u9 mod_ssl/2.2.22 OpenSSL/1.0.1e mod_perl/2.0.7 Perl/v5.14.2 configured -- resuming normal operations
[Thu May 29 01:19:00 2014] [info] Server built: Mar  4 2013 22:05:16
[Thu May 29 01:19:00 2014] [debug] prefork.c(1023): AcceptMutex: sysvsem (default: sysvsem)

我已确保启用每个虚拟主机并且a2ensite {sitename.conf}没有任何错误。

以下是配置文件的内容...

/etc/apache2/apache2.conf

# Global configuration
#
LockFile ${APACHE_LOCK_DIR}/accept.lock
PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
#              graceful restart. ThreadLimit can only be changed by stopping
#              and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# event MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

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

#
# 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.
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>


DefaultType None

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug

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

# Include list of ports to listen on and which to use for name based vhosts
Include ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
#
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

<Directory "/var/www">
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

# Include generic snippets of statements
Include conf.d/

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

/etc/apache2/sites-available/site1.net.conf

<VirtualHost *:80>
    ServerName site1.net
    ServerAlias site1.net *.site1.net
    DocumentRoot "/var/www/site1"
    ErrorLog "/var/www/site1/logs/error.log"
    CustomLog "/var/www/site1/logs/access.log" vhost_combined
    <Directory "/var/www/site1">
        Options None
        AllowOverride All
        Order allow,deny
        Allow from all
        Satisfy Any
    </Directory>
</VirtualHost>

/etc/apache2/sites-available/site2.com.conf

<VirtualHost *:80>
    ServerName site2.com
    ServerAlias site2.com *.site2.com
    DocumentRoot "/var/www/site2"
    ErrorLog "/var/www/site2/logs/error.log"
    CustomLog "/var/www/site2/logs/access.log" vhost_combined
    <Directory "/var/www/site2">
        Options None
        AllowOverride All
        Order allow,deny
        Allow from all
        Satisfy Any
    </Directory>
</VirtualHost>

我也尝试过设置 NameVirtualHost 如下:

Listen 80
NameVirtualHost 23.88.121.82:80
NameVirtualHost 127.0.0.1:80

以及 VirtualHost 指令:

<VirtualHost 23.88.121.82:80>
...
</VirtualHost>

对于两个站点来说,但这也会导致第一个站点发生故障。

我想知道是否需要为每个站点设置单独的 IP?我还有 2 个 IPv4 和 3 个 IPv6 地址可用,如果这样会有所不同的话。此外,从总体上讲,我需要为第一个站点启用 SSL。我读到我基本上只需要模仿监听端口 80 的指令,只监听端口 443,并确保 mod_ssl 已启用?

编辑:我刚刚apache2 -t以这种方式测试了配置文件,并收到错误:apache2: bad user name ${APACHE_RUN_USER}。但是,apachectl configtest返回Syntax OK。但是,其他地方没有提到互斥体的错误。我很确定,如果 apache 应该在其下运行的用户出现错误,服务器根本无法启动……

编辑2:重新启动 apache 修复了错误的用户名错误。

答案1

事实证明 DNS 设置存在问题,并且所有 Apache 配置都是正确的。:/

相关内容