Puppet / Vagrant:损坏的apache虚拟主机内容

时间:2012-10-02 09:17:48

标签: apache puppet vagrant

我正在使用vagrant / puppet来配置我的testmachine,我正在使用它为apache配置虚拟主机,但是当启动apache时我得到一个错误,显然是因为奇怪的间距或字符左右:

/apache2 start
 * Starting web server apache2                                                                                                                                                                                                                                            
Syntax error on line 4 of /etc/apache2/sites-enabled/my-ssl.localhost.conf:
Invalid command '\xc2\xa0\xc2\xa0ServerName', perhaps misspelled or defined by a module not included in the server configuration
Action 'start' failed.

我为配置虚拟主机而编写的清单文件如下所示

file {'hostfile4':
      path    => '/etc/apache2/sites-available/my-ssl.localhost.conf',
      ensure  => present,
      content => "
<VirtualHost *:443>
  DocumentRoot '/coding/mysite/htdocs/'
  ServerName foa-ssl.localhost
  ServerAlias foa-ssl.localhost
  ErrorLog /var/log/apache2/error.log
  CustomLog /var/log/apache2/access.log combined
  RewriteLog /var/log/apache2/rewrite.log
  RewriteLogLevel 0
    <Directory '/coding/mysite/checkout/htdocs'>
        AllowOverride All
        Options All -Indexes
        Order allow,deny
        Allow from all
        php_admin_value short_open_tag Off
        AddType application/x-httpd-php .css .js
    </Directory>
    <Directory '/coding/mysite/app_new/htdocs'>
        AllowOverride All
        Options All -Indexes
        Order allow,deny
        Allow from all
        php_admin_value short_open_tag Off
        AddType application/x-httpd-php .css .js
    </Directory>
  <Directory '/coding/mysite/cgi-bin'>
    Options +ExecCGI
  </Directory>
  SSLEngine on
  SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
</VirtualHost>",
    }

2 个答案:

答案 0 :(得分:3)

c2 a0(在错误消息中)是特殊字符“非破坏空间”的unicode代码,参见here

似乎apache根本不喜欢这样。所以你必须摆脱那些不间断的空间并使用普通空格,即使它在你的编辑器中看起来是一样的。

您可以使用NotePad ++并要求它将您的puppet文件转换为“ANSI”,这是一个更安全的配置文件编码。

在将内容移动到外部文件时,您必须在不知情的情况下清除它,但使用外部文件不是解决方案,即使它有效。

答案 1 :(得分:0)

使用它来解决它:

file { "/etc/apache2/sites-available/my-ssl.localhost.conf":
    mode => 440,
    owner => root,
    group => root,
    source => "/coding/puppetstuff/my-ssl.localhost.conf"
}

/coding/puppetstuff/foa-ssl.localhost.conf位于共享文件夹中(路径位于图片上)