Apache虚拟主机通过Internet显示空白页面,在本地工作正常

时间:2014-04-20 09:42:30

标签: php apache digital-ocean mod-fcgid suexec

在阅读完整的问题之前请不要回答:)

在新创建的DigitalOcean CentOS 6.5(64位)服务器中,我尝试通过发出以下命令创建两个Apache虚拟主机 - www.example-rose.comwww.example-tulip.com

服务器端设置

# software installation
yum install httpd mod_fcgid php-cli

# added cgi.fix_pathinfo=1 in /etc/php.ini
echo "cgi.fix_pathinfo=1" >> /etc/php.ini
echo "PHP_Fix_Pathinfo_Enable 1" >> /etc/httpd/conf.d/fcgid.conf

# added new users and groups for the two virtual sites
groupadd rose
groupadd tulip
useradd -s /bin/false -d /var/www/rose -m -g rose rose
useradd -s /bin/false -d /var/www/tulip -m -g tulip tulip
chmod 755 /var/www/rose
chmod 755 /var/www/tulip

# create new document root and make them own by respective users
mkdir -p /var/www/rose/web
chown rose:rose /var/www/rose/web
mkdir -p /var/www/tulip/web
chown tulip:tulip /var/www/tulip/web

既然我想通过SuEXEC运行PHP,我已经完成了为SuEXEC创建包装脚本的其他步骤

mkdir -p /var/www/php-fcgi-scripts/rose
mkdir -p /var/www/php-fcgi-scripts/tulip

# inside the wrapper, I added a file (/var/www/php-fcgi-scripts/rose/php-fcgi-starter) 
# with below content:
#!/bin/sh
PHPRC=/etc/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/bin/php-cgi

# changed the permission
chmod 755 /var/www/php-fcgi-scripts/rose/php-fcgi-starter
chown -R rose:rose /var/www/php-fcgi-scripts/rose
# above steps are repeated for tulip as well

最后,我在httpd.conf文件中添加了以下内容以启用虚拟主机

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName www.example-rose.com
  ServerAlias example-rose.com
  ServerAdmin webmaster@example-rose.com
  DocumentRoot /var/www/rose/web/
  <IfModule mod_fcgid.c>
    SuexecUserGroup rose rose
    <Directory /var/www/rose/web/>
      Options +ExecCGI
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/php-fcgi-scripts/rose/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    </Directory>
  </IfModule>
  ErrorLog /var/www/rose/error.log
  CustomLog /var/www/rose/access.log combined
  ServerSignature Off
</VirtualHost>

<VirtualHost *:80>
... similar lines for the second virtual host (Tulip). Cutting short ...
</VirtualHost>

我重新启动了服务器并将一个index.php文件放在web目录中,其中包含以下内容:<?php phpinfo(); ?>

本地计算机

为了测试虚拟主机,我使用curl

从本地计算机发出以下命令
$> curl -v -H "www.example-rose.com" 162.*.35.155/index.php
*   Trying 162.*.35.155...
* Connected to 162.*.35.155 port 80 (#0)
> GET /index.php HTTP/1.1
> User-Agent: curl/7.30.0
> Host: www.example-rose.com
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host 162.*.35.155 left intact
curl: (52) Empty reply from server

如果我尝试通过网络浏览器而非curl(在为域创建/etc/hosts条目后)进行访问,则会显示空白页面。服务器中未生成Apache Access日志或错误日志。如果我放置一个静态文件(而不是php文件),我可以访问静态文件而不会出现任何问题。但.php文件不起作用。

然而

当我尝试从 DigitalOcean服务器本身(或从DigitalOcean网络中的​​其他服务器)尝试curl时,我会看到带有phpinfo()的预期index.php结果没有任何问题。但是当我从DO网络外部尝试时,它不起作用。

我已经做了各种常见的故障排除(安装,重新安装,检查权限,一次又一次地检查conf文件等),我现在已经结束了。接下来是什么?

在阅读完整的问题之前请不要回答:)

0 个答案:

没有答案