Monday, March 03, 2008

Install SSL for apache

Setup Certificate

# from: http://www.vanemery.com/Linux/Apache/apache-SSL.html
[root]# openssl genrsa -des3 -out my-ca.key 2048
[root]# openssl req -new -x509 -days 3650 -key my-ca.key -out my-ca.crt

# deleted -des3 to not using pass phrase
[root]# openssl genrsa -out mars-server.key 1024
[root]# openssl req -new -key mars-server.key -out mars-server.csr
[root]# openssl x509 -req -in mars-server.csr -out mars-server.crt -sha1 -CA my-ca.crt -CAkey my-ca.key -CAcreateserial -days 3650

Setup Apache

# For no ssl
-bash-3.00$ more /opt/csw/apache2/etc/virtualhosts/yourserver.conf
<VirtualHost 8.17.170.154:80>
  ServerName youserver.com
  ServerAlias *.youserver.com
  DocumentRoot /home/youserver.com/app/current/public

  <Directory "/home/youserver.com/app/current/public/">
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
  </Directory>

  <Proxy balancer://yourserver-mongrels>
    BalancerMember http://127.0.0.1:8000
    BalancerMember http://127.0.0.1:8001
    BalancerMember http://127.0.0.1:8002
    BalancerMember http://127.0.0.1:8003
  </Proxy>

  ProxyPass /images !
  ProxyPass /javascripts !
  ProxyPass /stylesheets !
  ProxyPass / balancer://yourserver-mongrels/
  ProxyPassReverse / balancer://yourserver-mongrels/
  ProxyPreserveHost On
</VirtualHost>

# For ssl
-bash-3.00$ more /opt/csw/apache2/etc/virtualhosts/yourserver-ssl.conf

<VirtualHost 8.17.170.154:443>
ServerName youserver.com
ServerAlias *.youserver.com
DocumentRoot /home/youserver.com/app/current/public

<Directory "/home/youserver.com/app/current/public/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<Proxy balancer://yourserver-mongrels>
  BalancerMember http://127.0.0.1:8000
  BalancerMember http://127.0.0.1:8001
  BalancerMember http://127.0.0.1:8002
  BalancerMember http://127.0.0.1:8003
</Proxy>

ProxyPass /images !
ProxyPass /javascripts !
ProxyPass /stylesheets !
ProxyPass / balancer://yourserver-mongrels/
ProxyPassReverse / balancer://yourserver-mongrels/
ProxyPreserveHost On

SSLEngine On
SSLCertificateFile /home/youserver.com/ssl/mars-server.crt
SSLCertificateKeyFile /home/youserver.com/ssl/mars-server.key
</VirtualHost>

Saturday, March 01, 2008

Merb Console

Tried Merb Console

felix@Felix:~/Developments/kakei$ merb -i
 ~ loading gem 'activerecord' from config/init.rb:27 ...
 ~ loading gem 'merb_activerecord' from config/init.rb:27 ...
 ~ loading gem 'merb_rspec' from config/init.rb:36 ...
 ~ loading gem 'merb_helpers' from config/init.rb:39 ...
 ~ Loaded DEVELOPMENT Environment...
 ~ Connecting to database...
 ~ Compiling routes...
 ~ Using 'share-nothing' cookie sessions (4kb limit per client)
irb(main):035:0*
irb(main):036:0* merb
=> #<Merb::Rack::Console:0xb76f6604>
irb(main):037:0>
irb(main):038:0*
irb(main):039:0* merb.url(:payments)
=> "/payments"
irb(main):040:0> merb.url(:new_payment)
=> "/payments/new"
irb(main):041:0> merb.url(:delete_payment)
=> "/payments//delete"
irb(main):042:0> merb.url(:delete_payment, )
SyntaxError: compile error
(irb):42: syntax error, unexpected ')'
    from (irb):42
    from :0
irb(main):043:0> payment = Payment.find(1)
=> #<Payment id: 1, amount: 23423, paid_for: "34234", created_at: "2008-03-01 17:26:41">
irb(main):044:0> merb.url(:delete_payment, payment)
=> "/payments/1/delete"
irb(main):045:0> merb.url(:edit_payment, payment)
=> "/payments/1/edit"
irb(main):046:0> merb.url(:as_payment, payment)
RuntimeError: Named route not found: as_payment
    from /usr/lib/ruby/gems/1.8/gems/merb-core-0.9.1/lib/merb-core/dispatch/router.rb:90:in `generate'
    from /usr/lib/ruby/gems/1.8/gems/merb-core-0.9.1/lib/merb-core/rack/adapter/irb.rb:14:in `url'
    from (irb):46
    from :0
irb(main):047:0> merb.url(:payment, payment)
=> "/payments/1"
irb(main):003:0* merb.show_routes
Named Routes
  new_payment: /payments/new
  edit_payment: /payments/:id/edit
  payment: /payments/:id
  delete_payment: /payments/:id/delete
  payments: /payments
  custom_payment: /payments/:action/:id
Anonymous Routes
  /payments/?(\.:format)?
  /payments/index(\.:format)?
  /payments/new
  /payments/?(\.:format)?
  /payments/:id(\.:format)?
  /payments/:id[;/]edit
  /payments/:id[;/]delete
  /payments/:id(\.:format)?
  /payments/:id(\.:format)?
  /:controller(/:action(/:id)?)?(\.:format)?
=> nil