使用ruby修改apache httpd.conf

使用ruby修改apache httpd.conf,ruby,apache,Ruby,Apache,嘿,伙计们,我正在尝试使用ruby代码1.8.5在httpd.conf中进行更改,你能帮我一下吗 Apache配置文件必须专门配置Apache配置文件 对于已安装的服务器,即ServerName配置项必须设置为VM的IP地址,而不是127.0.0.1或任何其他通用地址。服务器管理员配置项必须设置为cit470-sp2014-TEAM您的团队_NUMBER@gmail.com. 如果需要,请创建一个同名的gmail帐户 我还没有这样做 SSL所有内容也必须使用URL的加密https版本进行访问 用

嘿,伙计们,我正在尝试使用ruby代码1.8.5在httpd.conf中进行更改,你能帮我一下吗

  • Apache配置文件必须专门配置Apache配置文件 对于已安装的服务器,即ServerName配置项必须设置为VM的IP地址,而不是127.0.0.1或任何其他通用地址。服务器管理员配置项必须设置为cit470-sp2014-TEAM您的团队_NUMBER@gmail.com. 如果需要,请创建一个同名的gmail帐户 我还没有这样做
  • SSL所有内容也必须使用URL的加密https版本进行访问
  • 用户目录配置服务器,以便单个用户可以创建自己的web 通过将文件放在其主目录的public_html子目录中来访问站点。这些文件应该可以通过表单和表单的URL访问。这可能需要您使用mod_rewrite创建重写规则

    ]# ./apconfigure.rb
    ./apconfigure.rb:8: warning: parenthesize argument(s) for future version
    ./apconfigure.rb:18: syntax error
    .gsub(/ServerAdmin (.+)/, "ServerAdmin cit470su2015team2@gmail.com")
     ^
    ./apconfigure.rb:19: syntax error
    .gsub(/UserDir disable/, "UserDir public_html")
     ^
    ./apconfigure.rb:20: syntax error
    .gsub(userdir_regex, replacement) + "\nServerName 10.2.7.84  \nRewriteEngine on\nRewriteRule ^/users/(.*)$ /~$1 [PT]"
     ^
    
  • 这是我的密码

      #!/usr/bin/ruby
      # This script edits the Apache configuration files and enables UserDir,
      # as well as a custom RewriteRule
      # path to apache config file
      config_file = "/etc/httpd/conf/httpd.conf"
    
      file = File.read(config _file)
    
      # regex to uncomment the sample UserDir directives
      userdir_regex = /#<Directory \/home\/\*\/public_html>.+?<\/Directory>/m
      replacement = file.match(userdir_regex).to_s.gsub('#','')
    
      # make some substitutions: change ServerName and ServerAdmin, enable UserDir,
      # add rewrite rules.
      edited_file =
         file
    
      .gsub(/ServerAdmin (.+)/, "ServerAdmin cit470su2015team2@gmail.com")
      .gsub(/UserDir disable/, "UserDir public_html")
      .gsub(userdir_regex, replacement) + "\nServerName 10.2.7.84 \nRewriteEngine on\nRewriteRule ^/users/(.*)$ /~$1 [PT]"
    
      # write the changes to the file
      File.open(config_file, 'w') do |f|
      f.puts edited_file
        end
    
    #/usr/bin/ruby
    #此脚本编辑Apache配置文件并启用UserDir,
    #以及自定义重写规则
    #apache配置文件的路径
    config_file=“/etc/httpd/conf/httpd.conf”
    file=file.read(配置文件)
    #regex取消对示例UserDir指令的注释
    userdir_regex=/#.+?/m
    replacement=file.match(userdir_regex).to_.gsub('#','')
    #进行一些替换:更改ServerName和ServerAdmin,启用UserDir,
    #添加重写规则。
    编辑的文件=
    文件
    .gsub(/ServerAdmin(+)/,“ServerAdmincit470su2015team2@gmail.com")
    .gsub(/UserDir disable/,“UserDir public_html”)
    .gsub(userdir\u regex,替换)+“\nServerName 10.2.7.84\nWriteEngine on\nWriteEnable^/users/(.*)$/~$1[PT]”
    #将更改写入文件
    打开(配置文件,'w')do | f|
    f、 放入已编辑的文件
    结束
    
    !但是无论如何,您有一个Ruby错误,但是您没有提供任何代码供我们查看。是的,我刚刚添加了代码。请看-您是否使用Ruby 1.9或更高版本。如果是这样,也许在<代码>文件>代码> >代码> > GSUB/COD>之间的空行(第17行)混淆了解析器,它决定语句在<代码>文件>代码下终止,所以请删除它。我使用Ruby 1.85(2006—0825)[I86Linux ],无论如何,我用BASH代码修复了我的程序,谢谢。