solve libxslt is missing error when installing omniauth or nokogiri

I was trying to install omniauth and was getting error for nokogiri libxslt is missing. If you are facing the same issue you may solve it using the following command. I have tested it with ubuntu and it worked for me. Its not tested on Fedora but should work.

on Ubuntu 10

sudo apt-get install libxml2 libxml2-dev libxslt libxslt-dev

on Ubuntu 11

sudo apt-get install libxml2 libxml2-dev libxslt1-dev

On fedora

sudo yum install libxml2-devel libxslt-devel

If you still face issues do write to me.

Thanks

Be Sociable, Share!

solving sudo: /etc/sudoers is mode 0777, should be 0440 error

Today one of my team mate accidently gave chmod -R 777 on all folders. So he was not able to do sudo su and login as a root user.

Now as a normal user it wont allow you to change the rights. This is a big headache. Ultimately I found the solution to this issue. Restart ur pc and press shift key which will give u an option to start your system in recovery mode.

Select that and you will get an option to login as root with command prompt. Now change the rights of /etc/sudoers to 0440 by using the command chmod 0440 /etc/sudoers. Exit and restart your system.

Now start your terminal and try sudo su to login as a root user. Ah! finally the problem got solved.

If you are still not able to solve this issue. Just write back to me and I shall help you out.

Njoi

Be Sociable, Share!

Generate self signed certificates for nginx

As i mentioned in my previous post that I will let u know how to generate self signed certificates here is the procedure for it.

First of all install ssl-cert using

sudo aptitude install ssl-cert

Next step is to create a private key using the command below.

openssl genrsa -des3 -out myssl.key 1024

Now create a CSR where you need to provide details such as Country, State, City, Orgainzation name, Unit Name, Common Name and Email id

openssl req -new -key myssl.key -out myssl.csr

And the last step is the actual certificate

openssl x509 -req -days 365 -in myssl.csr -signkey myssl.key -out myssl.crt

Thats it. So its just 3-4 steps. Now start configuring it with nginx using the link below

http://blog.dhavalparikh.co.in/2011/06/configure-self-signed-certificates-with-nginx-and-rails/

If you have any doubts please feel free to ask.

Be Sociable, Share!

Configure Self Signed Certificates with Nginx and Rails

Guys,

I was given a task to setup https using self signed certificate using nginx in our latest rails app. This was basically for the paypal page where we were accepting credit card details on our site.

Below is the nginx.conf file configuration which u require in order to implement SSL certificate. If you see closely there are 2 port defined. 1) port 80 2) port 443. Port 80 is for standard http request and port 443 is for https request.

#————————code starts below————————————-

#user nobody;

worker_processes 4;

pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;

default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] ‘
‘”$request” $status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

sendfile on;
tcp_nopush on;
tcp_nodelay off;
#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript ;

upstream main{
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}

server {
listen 80;
#server_name yourdomain.com;

#client_max_body_size 4M;
client_body_buffer_size 128k;
root /var/www/yourapplication/public/;

# needed to forward user.s IP address to rails
proxy_set_header X-Real-IP $remote_addr;

# needed for HTTPS
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
proxy_max_temp_file_size 0;

location ~ ^/(images|javascripts|stylesheets|product)/ {
expires 10y;
}

# If the file exists as a static file serve it directly without
# running all the other rewite tests on it
if (-f $request_filename) {
break;
}

# check for index.html for directory index
# if its there on the filesystem then rewite
# the url to add /index.html to the end of it
# and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
# redirect the traffic to the upstream mongrel defined as .main.
proxy_pass http://main/;
}
}

#———————–https————

server {
listen 443;
server_name yourdomain.com;
ssl on;
ssl_certificate /etc/ssl/certs/myssl.crt;
ssl_certificate_key /etc/ssl/private/myssl.key;

#client_max_body_size 4M;
client_body_buffer_size 128k;
root /var/www/yourapplication/public/;

# needed to forward user.s IP address to rails
proxy_set_header X-Real-IP $remote_addr;

# needed for HTTPS
proxy_set_header X_FORWARDED_PROTO https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Url-Scheme $scheme;
proxy_redirect off;
proxy_max_temp_file_size 0;

location ~ ^/(images|javascripts|stylesheets|product)/ {
expires 10y;
}

# If the file exists as a static file serve it directly without
# running all the other rewite tests on it
if (-f $request_filename) {
break;
}

# check for index.html for directory index
# if its there on the filesystem then rewite
# the url to add /index.html to the end of it
# and then break to send it to the next config rules.
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
# redirect the traffic to the upstream mongrel defined as .main.
proxy_pass http://main/;
}
}

#—————————-https———————–

In the code above the most important part is

ssl on;
ssl_certificate /etc/ssl/certs/myssl.crt;
ssl_certificate_key /etc/ssl/private/myssl.key;

Now how to generate self signed certificates i will let u know in my next post. (Though i should have covered it b4 but ne ways will do it now)

Thats all. You can add and remove basic paraments you want from the above given nginx.conf file.
Let me know if you find any issues in implementing SSL for your app.

Be Sociable, Share!

you are being redirected error with rails 2.3.8, mongrel and nginx

Guys if you get this error you are being redirected while working with rails 2.3.7 + nginx + mongrel
in production mode. Just add the code below in the initializer folder in a file called mongrel.rb

if Rails.version == ‘2.3.8’ && Gem.available?(‘mongrel’, Gem::Requirement.new(‘~>1.1.5’))
&& self.class.const_defined?(:Mongrel)

# Pulled right from latest rack. Old looked like this in 1.1.0 version.
#
# def [](k)
# super(@names[k] ||= @names[k.downcase])
# end
#
module Rack
module Utils
class HeaderHash < Hash
def [](k)
super(@names[k]) if @names[k]
super(@names[k.downcase])
end
end
end
end

# Code pulled from the ticket above.
#
class Mongrel::CGIWrapper
def header_with_rails_fix(options = ‘text/html’)
@head[‘cookie’] = options.delete(‘cookie’).flatten.map { |v| v.sub(/^\n/,”) } if options.class != String and options[‘cookie’]
header_without_rails_fix(options)
end
alias_method_chain :header, :rails_fix
end

# Pulled right from 2.3.8 ActionPack. Simple diff was
#
# if headers.include?(‘Set-Cookie’)
# headers[‘cookie’] = headers.delete(‘Set-Cookie’).split(“\n”)
# end
#
# to
#
# if headers[‘Set-Cookie’]
# headers[‘cookie’] = headers.delete(‘Set-Cookie’).split(“\n”)
# end
#
module ActionController
class CGIHandler
def self.dispatch_cgi(app, cgi, out = $stdout)
env = cgi.__send__(:env_table)
env.delete “HTTP_CONTENT_LENGTH”
cgi.stdinput.extend ProperStream
env[“SCRIPT_NAME”] = “” if env[“SCRIPT_NAME”] == “/”
env.update({
“rack.version” => [0,1],
“rack.input” => cgi.stdinput,
“rack.errors” => $stderr,
“rack.multithread” => false,
“rack.multiprocess” => true,
“rack.run_once” => false,
“rack.url_scheme” => [“yes”, “on”, “1”].include?(env[“HTTPS”]) ? “https” : “http”
})
env[“QUERY_STRING”] ||= “”
env[“HTTP_VERSION”] ||= env[“SERVER_PROTOCOL”]
env[“REQUEST_PATH”] ||= “/”
env.delete “PATH_INFO” if env[“PATH_INFO”] == “”
status, headers, body = app.call(env)
begin
out.binmode if out.respond_to?(:binmode)
out.sync = false if out.respond_to?(:sync=)
headers[‘Status’] = status.to_s
if headers[‘Set-Cookie’]
headers[‘cookie’] = headers.delete(‘Set-Cookie’).split(“\n”)
end
out.write(cgi.header(headers))
body.each { |part|
out.write part
out.flush if out.respond_to?(:flush)
}
ensure
body.close if body.respond_to?(:close)
end
end
end
end

end

Thats all just restart your server nginx and mongrel cluster and the error should be gone.

Be Sociable, Share!

Deploying Rails Application on Amazon Ec2

Hello guys

Posting after a long time. But any ways below are the steps if you want to deploy a rails app on ec2 directly without using any 3rd party service providers

All the details mentioned below after for ubuntu so path might vary for other Linux flavours.

step 1 = Set java home. Ofcourse you need to have java installed and I assume that you already have it installed.

JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

Step 2 = login to amazon aws go to the account tab and download security credentials.  You will see 2 things

1) private key 2) certificate

Download them and store it on some path like /home/dhaval/cert or whatevery

Than export the keys and set it up with the following commands

export EC2_PRIVATE_KEY=/home/dhaval/cert/pk-2spdXHCQ4HDMJNCULJB5NA4JNLE7SWOR.pem
export EC2_CERT=/home/dhaval/cert/cert-2spdJXHCQ4HDMJNCULJB5NA4JNLE7SWOR.pem

Step 3 = Download api tools available on aws site

http://aws.amazon.com/developertools/351?_encoding=UTF8&jiveRedirect=1

export it and set the path

export EC2_HOME=/home/dhaval/cert/ec2-api-tools-1.3-62308
export PATH=$EC2_HOME/bin:$PATH

Step 4 = set up ssh keys using the following commands

ec2-add-keypair gsg-keypair

Now save this generated kaypair in ~/.shh folder with name id_rsa-gsg-keypair

Step 5 = Start an instance using the command below

ec2-run-instances (ami instance name) -k gsg-keypair

Step 6 = Check status of the instance

check status with

ec2-describe-instances (instant name)

eg.

ec2-describe-instances i-10a64379

Step 7 = Authorization of network ports using commands as below

ec2-authorize default -p 22
ec2-authorize default -p 80

Step 8 = Connect to your instance using the command below

ssh -i id_rsa-gsg-keypair root@machine_name

Thats all once these steps are done you can see the instance running on the aws console.

Than install ruby gems + rails + other required gems and packages and you are set to go.

In order to upload your files you can use Capistrano or also you can ssh through ftp using the key specified.

Hope this helps. If you are stuck at any step do feel free to ask question and I shall get back to you.

Njoi

Be Sociable, Share!
1 2 3 4 5 6 27