blog install 2 postgresql and rails
It’s the continuation of the previous article on my blog installation. Here with postgresql and nginx setup.
postgresql configuration
configure postgres user .bash_profile :
export PATH=$PATH:/usr/lib/postgresql/9.1/bin
export PGDATA="/var/lib/postgresql/9.1/main"
Then we will create a djouxblog user in postgresql.
sudo su - postgres
psql
create role djouxblog with createdb login password 'mypass';
# TYPE DATABASE USER ADDRESS METHOD
local postgres djouxblog password
local djouxblog_development djouxblog password
local djouxblog_production djouxblog password
the djouxblog user will be able to create the differents databases.
We need to start postgresql and add automatic postgresql start at system boot :
update-rc.d postgresql defaults
install application
First clone the application :
git clone https://github.com/adejoux/djouxblog.git
Install packages dependencies and run bundle install
sudo aptitude install libmagickcore-dev libmagickwand-dev
bundle install
copy the sample database configuration file :
cp config/database.yml.sample config/database.yml
Edit the configuration for each database :
development:
adapter: postgresql
encoding: unicode
database: djouxblog_development
pool: 5
username: djouxblog
password: mypass
template: template0
Generate the application configuration file :
cp config/application.example.yml config/application.yml
Edit the parameters :
ADMIN_NAME: First User
ADMIN_EMAIL: user@example.com
ADMIN_PASSWORD: changeme
ROLES: [admin, user, VIP]
#google analytics settings
GA_ACCOUNT: 'changeme'
GA_SITE: 'http://changeme'
Create the databases :
rake db:setup
And for production :
RAILS_ENV="production" rake db:setup
nginx configuration
Install nginx on ubuntu :
sudo aptitude install nginx-full
The application provides a nginx sample configuration file in nginx/nginx.conf.
upstream unicorn {
server unix:/tmp/unicorn_djouxblog.socket fail_timeout=0;
}
server {
listen 80;
server_name www.myserver.com;
root /www/djouxblog/public;
server_tokens off;
location / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
access_log off;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
}
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
You can copy it in /etc/nginx/sites-available. After modification, you can enable it and test the configuration :
cp /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled
/etc/init.d/nginx configtest
/etc/init.d/nginx restart
start application
If you want to test it in development, only run :
rails s
For production, we need to compile the assets :
rake assets:precompile
And start unicorn :
bundle exec unicorn -c config/unicorn.rb -E production -D