Apache 看不到网站 - CentOS 7

Apache not seeing website - CentOS 7

我在 Ubuntu 中设置了很多虚拟主机,但今天我需要在 CentOS 7 服务器上执行此操作。我安装了 Apache 并设置了 VHost 配置,但当我查看该站点时没有任何显示。

我知道 Apache 正在读取我的配置文件,因为如果我在其中添加错误并重新启动 Apache,它会抱怨错误。 CentOS 7 是否需要 "else"?

你想实现什么样的虚拟主机?我猜是基于名字的。

如果您不是 运行 版本 2.4>,那么您需要为 IP:PORT 对

启用名称虚拟主机指令

名称虚拟主机 *:80

不同的行为可能取决于发行版附带的不同版本的 Apache 服务器。

如果不是,可能是selinux标签设置不正确。无论如何,在这种情况下,您都会遇到权限错误。老实说,我不相信是这样。

这是我在 CentOS 7.3.1611 运行 Apache 2.4.6 上使用的设置 我通常使用 virtualmin / webmin 进行配置,但我查看了 httpd.conf 基本设置在我的配置中是

<VirtualHost xxx.xxx.xxx.xxx:80>
SuexecUserGroup "#502" "#502"
ServerName grid.hosted-systems.co.uk
ServerAlias www.grid.hosted-systems.co.uk
ServerAlias webmail.grid.hosted-systems.co.uk
ServerAlias admin.grid.hosted-systems.co.uk
DocumentRoot /home/grid/public_html
ErrorLog /var/log/grid.hosted-systems.co.uk_error_log
CustomLog /var/log/grid.hosted-systems.co.uk_access_log combined
DirectoryIndex index.html index.htm index.php index.php4 index.php5

<Directory /home/grid/public_html>
    Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
    allow from all
    AllowOverride All   Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
    AddType application/x-httpd-php .php
    AddHandler fcgid-script .php
    AddHandler fcgid-script .php5
    FCGIWrapper /home/grid/fcgi-bin/php5.fcgi .php
    FCGIWrapper /home/grid/fcgi-bin/php5.fcgi .php5
</Directory>

<Directory /home/grid/cgi-bin>
    allow from all
    AllowOverride All   Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
</Directory>

RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.grid.hosted-systems.co.uk
RewriteRule ^(.*) https://grid.hosted-systems.co.uk:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.grid.hosted-systems.co.uk
RewriteRule ^(.*) https://grid.hosted-systems.co.uk:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
    php_admin_value engine Off
FcgidMaxRequestLen 1073741824
Alias /dav /home/grid/public_html

<Location /dav>
    DAV on
    AuthType Basic
    AuthName "grid.hosted-systems.co.uk"
    AuthUserFile /home/grid/etc/dav.digest.passwd
    Require valid-user
    ForceType text/plain
    Satisfy All
    RemoveHandler .php
    RemoveHandler .php5
    RewriteEngine off
</Location>

<Files awstats.pl>
    AuthName "grid.hosted-systems.co.uk statistics"
    AuthType Basic
    AuthUserFile /home/grid/.awstats-htpasswd
    require valid-user
</Files>
</VirtualHost>

<VirtualHost xxx.xxx.xxx.xxx:80>
SuexecUserGroup "#500" "#500"
ServerName mirrors.hosted-systems.co.uk
ServerAlias www.mirrors.hosted-systems.co.uk
ServerAlias webmail.mirrors.hosted-systems.co.uk
ServerAlias admin.mirrors.hosted-systems.co.uk
DocumentRoot /home/hosted-systems/domains/mirrors.hosted-systems.co.uk/public_html
ErrorLog /var/log/virtualmin/mirrors.hosted-systems.co.uk_error_log
CustomLog /var/log/virtualmin/mirrors.hosted-systems.co.uk_access_log combined
ScriptAlias /cgi-bin/ /home/hosted-systems/domains/mirrors.hosted-systems.co.uk/cgi-bin/
ScriptAlias /awstats/ /home/hosted-systems/domains/mirrors.hosted-systems.co.uk/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5

<Directory /home/hosted-systems/domains/mirrors.hosted-systems.co.uk/public_html>
    Options +Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
    AddType application/x-httpd-php .php
    AddHandler fcgid-script .php
    AddHandler fcgid-script .php5
    FCGIWrapper /home/hosted-systems/domains/mirrors.hosted-systems.co.uk/fcgi-bin/php5.fcgi .php
    FCGIWrapper /home/hosted-systems/domains/mirrors.hosted-systems.co.uk/fcgi-bin/php5.fcgi .php5
</Directory>

<Directory /home/hosted-systems/domains/mirrors.hosted-systems.co.uk/cgi-bin>
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
</Directory>

Alias "/centos" "/home/shared/CentOS"
    <Directory "/home/shared/CentOS">
            Options +Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
            Require all granted
            HeaderName HEADER.html
    </Directory>

Alias "/centos/" "/home/shared/CentOS/"
    <Directory "/home/shared/CentOS/">
            Options +Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
            IndexOptions FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=*
            Require all granted
            HeaderName HEADER.html
    </Directory>
</VirtualHost>

这里的设置使用端口 80 设置了两个虚拟网站并绑定到同一个 IP,这可以通过使用 http://servername or http://ServerAlias 访问 DocumentRoot 是要作为服务器的文件的位置。 第二个 VirtualServer 的设置基本相同,但它也显示了如何使用 Alias 部分从主目录外部提取文档。

附带说明一下,如果有人在发布的内容中发现任何漏洞,请告诉我或编辑并告诉我。

琥珀玛丽

所以答案是 CentOS 服务器(默认情况下)阻止了 HTTP 端口 80。这看起来确实有点傻,但是一旦我允许防火墙为网络流量打开这些端口,所有工作正常:

iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT

我在 Centos 7.5 上尝试 firewall-cmd --add-service=http,它工作正常