前一篇文章介绍了mcomaster的部署,完成后默认是以webrick http方式运行,监听3000端口,这个跟之前说的puppet-dashboard部署时一样,应该说rails程序默认都以这种方式运行。
webrick本身效率并不好,另外我们很多时候不希望服务器开多余的端口,本文就介绍如何以apache的方式运行rails程序。
一、安装passenger
需要为apache安装passenger模块,可以采用yum安装,这里使用gem安装
# gem install passenger 完成后找到 passenger-install-apache2-module 运行 # passenger-install-apache2-module
二、配置虚拟主机
这里将配置一个虚拟主机,用来运行mcomaster
# vim /etc/httpd/conf.d/passenger.conf LoadModule passenger_module /usr/ruby/lib/ruby/gems/2.1.0/gems/passenger-4.0.46/buildout/apache2/mod_passenger.so #需要跟你的环境调整 <IfModule mod_passenger.c> PassengerRoot /usr/ruby/lib/ruby/gems/2.1.0/gems/passenger-4.0.46 #同上 PassengerDefaultRuby /usr/ruby/bin/ruby </Ifmodule> <VirtualHost 192.168.11.170:80> ServerName mcomaster.wofei DocumentRoot "/usr/mcomaster-master/public/" #mcomaster的路径,注意写对 <Directory "/usr/mcomaster-master/public/"> Options None AllowOverride AuthConfig Order allow,deny allow from all </Directory> </VirtualHost>
另外还需要配置/etc/httpd/conf/httpd.conf中的NameVirtualName
NameVirtualHost 192.168.11.170:80
然后重启apache,应该可以访问了。启动的时候我遇到过两个问题,如果你也遇到可以参考解决方法
1、apache对mod文件的执行权限,报如下错误
Starting httpd: httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.d/passenger.conf: Cannot load /usr/ruby/lib/ruby/gems/2.1.0/gems/passenger-4.0.46/buildout/apache2/mod_passenger.so into server: /usr/ruby/lib/ruby/gems/2.1.0/gems/passenger-4.0.46/buildout/apache2/mod_passenger.so: failed to map segment from shared object: Permission denied
解决方法:http://stackoverflow.com/questions/20919771/centos-6-4-failed-to-map-segment-from-shared-object-permission-denied
2、SELinux导致无法绑定其他端口,起初我用80端口,mcomaster的虚拟主机配置不起作用,换成8081才发现这个错误,然后设置了后又改回80端口发现mcomaster也可以正常访问
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:8081 (13)Permission denied: make_sock: could not bind to address 0.0.0.0:8081 no listening sockets available, shutting down
解决方法:http://blog.itechol.com/space-33-do-blog-id-5114.html
最后添加本机映射,访问试试吧