Nginx Http to Https redirection for particular URL’s

Tags

, , , , , ,

In our application there was a need to redirect few url’s to https and others back to http. So for e.g. i had to redirect sign-in, sign-up, etc to https and other url’s  back to http.

Following are the things that i configured in nginx.conf to get it working.

#Section for http
server {
listen       80;
server_name  http://www.example.com;
root /path-to-public-folder-of-project;
passenger_enabled on;

location ~ ^/(sign-up|sign-in) {
return 301 https://$host$request_uri;
}
}

#Section for https
server {
listen       443;
server_name  http://www.example.com;
root /path-to-public-folder-of-project;
passenger_enabled on;

ssl                  on;
ssl_certificate      /usr/local/nginx/ssl/example.com.crt;
ssl_certificate_key  /usr/local/nginx/ssl/example.key;
ssl_session_timeout  5m;
ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers   on;

# Redirect all other requests to HTTP.
location ~ ^(?!/(sign-up|sign-in)) {
return  301 http://$host$request_uri;
}
}

The above configuration worked perfectly for me. Only specific url’s were being served through https and remaining through http.

Install Imagemagick on Centos 6.4

Tags

, , , ,

1. Install needed libraries

sudo yum install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype-devel libtiff-devel

2. Create a directory and download source.

mkdir imagemagick
cd /imagemagick
wget ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.8.6-7.tar.gz

3. Untar the compressed file

tar zxvf ImageMagick-6.8.6-7.tar.gz
cd ImageMagick-6.8.6-7

4. Configure & Make & Install

sudo ./configure –prefix=/usr/ –with-bzlib=yes –with-fontconfig=yes –with-freetype=yes –with-gslib=yes –with-gvc=yes –with-jpeg=yes –with-jp2=yes –with-png=yes –with-tiff=yes
sudo make
sudo make install

5. To test if its running

$which convert  should show
/usr/bin/convert

or use below command to check version.

$ /usr/bin/convert –version
Version: ImageMagick 6.8.6-7 2013-07-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib freetype gslib jng jpeg png ps tiff zlib

Note: If while using with rails it gives error related to “libMagickCore-6.Q16.so.1” then use below command to fix it.

$sudo ldconfig /usr/local/lib

Setup a Rails App to use both Mongodb and Mysql together

Tags

, , ,

You can use Mysql and Mongodb in one application.

1. Create a rails app using mysql.

2. Next, add following to your Gemfile, and run bundle install:

gem "mongoid", "~> 2.3"
gem "bson_ext", "~> 1.4"

Now, you’re almost ready to go, but you still need some configuration info. Generate config/mongo.yml by running:

rails generate mongoid:config

This will create a mongo.yml where you can configure it to use as per the development environment.

Configure Rails’ model generator. Inside of the Application class (config/application.rb)  add:

config.generators do |g|
  g.orm :mongoid
end
This will allow you to use the rails generate model command with Mongoid.
For using Mongomapper instead of Mongoid refer,
For more details regarding usage of Mongoid refer,

Solr installation on centos 6

Tags

, , , , , , , ,

Basic pre-requirements are,

1. Java and Tomcat should be installed.

Installing Solr,

1. Download the required version from http://archive.apache.org/dist/lucene/solr/

i used 3.6.2

wget http://archive.apache.org/dist/lucene/solr/3.6.2/apache-solr-3.6.2.tgz

2. Extract the tgz file

tar xzvf apache-solr-3.6.2.tgz

3. Copy solr directory from  apache-solr-3.6.2/example/   to   /opt

sudo mv apache-solr-3.6.2/example/solr /opt/solr

4. Copy apache-solr-3.6.2.war  from apache-solr-3.6.2/dist/   to   /opt/solr

sudo mv apache-solr-3.6.2/dist/apache-solr-3.6.2.war /opt/solr/

5. Edit /opt/solr/conf/solrconfig.xml and change dataDir to

${solr.data.dir:/opt/solr/data}

7. Next create solr.xml for tomcat

cd /usr/local/tomcat/apache-tomcat-7.0.35/conf/Catalina/localhost/

Note: The above directory structure will change as per tomcat installation.

sudo vim solr.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<Context docBase=”/opt/solr/apache-solr-3.6.2.war” debug=”0″    crossContext=”true”>
<Environment name=”solr/home” type=”java.lang.String” value=”/opt/solr”  override=”true”/>
</Context>

9. Restart tomcat and you can check

http://your-ip:8080/solr (given that 8080 is not closed)

Solr Installation on Ubuntu

Tags

, , , , ,

You may need to install pre-required libraries as per your system requirements, if any of the following command fails.

Install Java (if not already installed)

Because tomcat and solr are Java based softwares we need the Java environment

$ sudo apt-get install openjdk-6-jdk

Install Tomcat & Solr

$ sudo apt-get install solr-tomcat

It will take care of installing both Tomcat & Solr, plus the integration of Solr in Tomcat.

start the server

$ sudo service tomcat6 start
  • Solr server responds at http://localhost:8080/solr
  • and the config & index will be stored at : /usr/share/solr/