简体   繁体   English

Apache没看到网站-CentOS 7

[英]Apache not seeing website - CentOS 7

I have setup a lot of Virtual Hosts in Ubuntu but today I needed to do this on a CentOS 7 server. 我已经在Ubuntu中设置了很多虚拟主机,但是今天我需要在CentOS 7服务器上执行此操作。 I installed Apache and setup the VHost config but nothing appears when I view the site. 我安装了Apache并设置了VHost配置,但是在查看站点时什么也没有显示。

I know that Apache is reading my Config files because if I add a fault in it and restart Apache, it complains about the error. 我知道Apache正在读取我的配置文件,因为如果在其中添加错误并重新启动Apache,它将抱怨该错误。 Is there something "else" that is needed on CentOS 7? CentOS 7是否需要“其他”?

What kind of virtualhosts are you trying to achieve? 您要实现哪种虚拟主机? name based I guess. 基于名称,我猜。

If you are not running on version 2.4> then you need to enable the name virtual host directive for the IP:PORT pair 如果您未在版本2.4>上运行,则需要为IP:PORT对启用名称虚拟主机指令

NameVirtualHost *:80 名称VirtualHost *:80

The different behavior can depend on the different versions of the Apache servers shipped with the distro. 不同的行为可能取决于发行版附带的Apache服务器的不同版本。

If not, it could be depending on selinux labels not being set properly. 如果没有,那可能取决于未正确设置selinux标签。 In this case anyway, you would get a permission error. 无论如何,您将得到一个权限错误。 Honestly I don't believe this is the case. 老实说,我认为情况并非如此。

This is the settings that I use on a CentOS 7.3.1611 running Apache 2.4.6 I normally use virtualmin / webmin for configuration, but I have looked at the httpd.conf The basic settings that are in my config are 这是我在运行Apache 2.4.6的CentOS 7.3.1611上使用的设置,我通常使用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>

The settings here set up two virtual websites using port 80 and bound to the same single IP , this is accessable by using http://servername or http://ServerAlias The DocumentRoot is the location of the files to be servers. 此处的设置使用端口80设置了两个虚拟网站,并绑定到相同的单个IP,这可以通过使用http:// servernamehttp:// ServerAlias访问。DocumentRoot是要用作服务器的文件的位置。 The second VirtualServer is basically the same set up, but it also shows how the Alias section can be used to pull documents from outside the main directory. 第二个VirtualServer基本上是相同的设置,但是它还显示了Alias部分如何可用于从主目录外部提取文档。

As a side note, if anyone spots any vunerabilities in what is posted, let me know or edit and let me know. 附带说明一下,如果有人发现发布的内容中存在任何漏洞,请让我知道或编辑并告诉我。

Amber-Marie 琥珀 - 玛丽·

So the answer to this was that the CentOS server had (by default) blocked the HTTP port 80. This really seems a bit silly but as soon as I allowed the firewall to open these ports for the web traffic, all worked fine: 因此,答案是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 ,它可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM