Centos, Varnish, NGINX, Drupal

As an experiment this week I decided to change the web server of a site to NGINX, the existing web server was Apache. I would like to share the steps required to setup NGINX with Varnish to make your Drupal site run at a blazing speed.
Environment:
Centos 6
16G RAM
Quadcore processor.
Install NGINX
yum install nginx
Configure NGINX
Open /etc/nginx/nginx.conf
Add the following lines at the bottom of “http” block:

It will look something like:

Add host yoursitename.com
Create two directories sites-available and sites-enabled

Create a file named “yoursitename.com.conf” under sites-available and paste the following contents:


Please note that the port number is “81” as varnish will run at port 80 and will behave like content server.

Create a symlink and remove the default configuration:

Please note that default.conf’s location can be different based on different platforms.

Change owner of the web directory

Install Varnish


Configure Varnish

Open /etc/sysconfig/varnish, replace the following values:

Keep all other values as it is.

Open /etc/varnish/default.vcl and update “backend default” block to the following:

Install PHP FPM

I am also using php fpm for faster php processing. Here is the command for that, simple simple

Restart servers:

Configure Varnish with Drupal

Install Drupal’s varnish module
Add the following lines to your settings.php:

Go to varnish configuration: admin /config /development /varnish

Set Varnish control terminal: 127.0.0.1:6082
Set Varnish Control key from/etc/varnish/secret
Please make sure the “Varnish running” is ticked.
Awesome, you are done. Enjoy the faster response times of your site.
Please comment if you have any feedback

Guide: How to Deploy Meteor / Telescope on Centos

Deploying meteor or telescope can be tricky sometimes especially when it comes to centos support. Here are the steps I am following to deploy my meteor app.

Development Environment:

  • OSX

Production Environment:

  • Linode 1GB
  • Centos 7
  • Apache

Software Stack on production:

  • Mongo DB
  • Node.js 0.10.35
  • NodeJS “Forever” module to start application in the background

I am not using NGINX as most of the people suggest as I already have a lot of applications running on Apache.

Just make sure that all the development libraries are available:

 Install Node.js

Install MongoDB

Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:

For 64 bit:

For 32 bit:

And:

The server setup is done. Please don’t need that you don’t need to install meteor or telescope in your production environment.

Package your app

On your local (development) machine, go to your meteor / telescope app directory and enter the following command:

It will build a new directory in your app directory named “yourapp_prod” It contains the bundle of your app. Compress yourapp_prod and upload to your servers home directory.

Push app to server

Make sure the port is free. If it is not free, you can use 3000 instead of 8080. Uncompress the file in your server’s /home directory and try start your app in the following series of commands:

It might give the following error that I am not sure about:
/home/yourapp_prod/bundle/programs/server/node_modules/fibers/future.js:173
throw(ex);
^
Error: /home/yourapp_prod/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at bindings (/home/yourapp_prod/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/node_modules/bindings/bindings.js:74:15)
at Object.<anonymous> (/home/yourapp_prod/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/bcrypt.js:1:97)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

But there is a fix for that:

Let’s try to run the app again:

It should work ok now. Try to enter http://yourapp_domain:8080/ in the browser and it should work.

But the problem is if you quit your terminal, your app will stop working. You can install node “forever” module to run your app in the background.

But you don’t want to make it work with http://yourapp_domain:8080/, you want to make it work with http://yourapp_domain/

You can configure a reverse proxy in your apache configuration. In case of Centos 7, you need to create some file like /etc/httpd/conf.d/yourapp_domain.conf. The contents of the file will be something like:

In my case, the app is running at port 8080, you can change the port number accordingly.

Restart apache now and your are DONE.

If you want more support or want to hire me, feel free to write in comments on write me directly at ping@qasimzeeshan.com