1

我正在使用 vagrant/puppet 来配置我的测试机,我正在使用它来为 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>",
    }
4

2 回答 2

3

c2 a0(在错误消息中)是特殊字符“不间断空格”的 unicode 代码,参见。在这里

看来apache根本不喜欢那样。所以你必须去掉那些不间断的空格并使用正常的空格,即使它在你的编辑器中看起来是一样的。

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

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

于 2012-10-10T14:52:47.143 回答
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 位于共享文件夹中(路径在图像上)

于 2012-10-02T12:44:48.660 回答