0

I tried with below code in apache cookbook to map default port 80 to 443 however still I get error while running the chef. Can you please suggest on this. I tried to map to other than port # 80 since I have nginx recipe also in my cookbook so would like to set up apache2 to listen on diff port -

* apache/attribute/default.rb

default['apache']['dir']          = '/etc/apache2'
default['apache']['listen_ports'] = [ '80','443' ]

* apache/recipes/default.rb

package "apache2" do
    action :install
end

service "apache2" do
    action [:enable, :start]
end


template "/var/www/index.html" do
    source "index.html.erb"
    mode "0644"
end

Vagrant provision error -
    ================================================================================
    ==> default:     
    ==> default: Error executing action `start` on resource 'service[apache2]'
    ==> default:     
================================================================================

    ==> default:     
    ==> default: Mixlib::ShellOut::ShellCommandFailed
    ==> default:     
    ==> default: ------------------------------------
    ==> default:     
    ==> default: Expected process to exit with [0], but received '1'


This time I had used  ==> 
attribute/default.rb with below content but still getting error -
default['apache']['dir']          = '/etc/apache2'
default['apache']['listen_ports'] = [ '81’ ]

Error    
==> default: STDOUT: * Starting web server apache2
==> default: 
==> default:     Action 'start' failed.
==> default:     The Apache error log may have more information.
==> default:        ...fail!
==> default:     STDERR: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
==> default:     (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
raj
  • 137
  • 1
  • 1
  • 10

1 Answers1

0

listen_ports is not a mapping, it sets which ports to listen on. If you don't want to listen on 80, do not include it in that array.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Please add log content to the question, it gets reformatted into a single line in here. – coderanger Jan 01 '16 at 21:11
  • After doing changes got a diff error and added the error message in above question. – raj Jan 01 '16 at 21:19
  • The new error is saying something already is listening on that port (80), so somewhere port 80 is still being used. – Martin Jan 01 '16 at 21:31
  • I think you are confused about which cookbook you are using. You mention the `apache2` cookbook, but your paths say `apache` which are very different. The one you want to be using is `httpd`. – coderanger Jan 01 '16 at 21:31
  • On port 80 I have nginx listening therefore I was trying to map apahce2 on port 81. I have vagrant machine ubuntu so I am not using httpd but using apache. I tried with default['apache2']['listen_ports'] = [ '81' ] but still same error. Also this time I had manually changed /etc/apache2/sites-enabled/000-default.conf and set and /etc/apache2/ports.conf and set Listen 81 then it work but I am looking to this to be done by chef in automated way. – raj Jan 01 '16 at 22:06
  • Again, you are using the wrong cookbook. You are reading the documentation for the `apache2` cookbook but using a different one. – coderanger Jan 01 '16 at 22:53
  • And the `httpd` cookbook works fine on Ubuntu, just use it as described in its docs. – coderanger Jan 01 '16 at 22:53